I have just started a new class at my university and it kind of has jumped straight into C without learning all the syntax and semantics (which isn't too bad to pick up on). However the one big difference compared to languages I do understand (java, python) are the concept of pointers.
I know that:
& - Address of something
* - value stored at the address of something
So if I have a string like:
char a[] = "ABCDEF";
Does 'a' have an address associated with it (&a) and if I do (*a) does it reference the entire string? The first character in the 'array' (A)?
Going off that thought seeing how it is a char [] does every single character in the string have its own address?
My eventual goal is to write a function that can manipulate pointers in order to locate the first character in one string that matches the character in a second string.
Am I on the right track? Note this is all pseudocode since I still am trying to learn C syntax
#include <stdio.h>
int main() {
create address to 'a'
create address to 'b'
make 'a' a string like "abcdefg"
make 'b' a string like 'b'
call findMatch(a,b); //pass in both to a function
return 0; // I know I have to have this at the end
}
void findMatch(char a, char b){
Retrieve the pointer to the first character in the 'a' string
Increment through 'a' to see if it matches the dereferenced b
If 'a' contains 'b' print its in the string as well as the address of the location in 'a'
}
example run - findMatch("abcdef","f") gives a print statement that says 'f' is in 'abcdef' and the address location of 'f'
I have read there are build in libraries with string functions in C but I want to manipulate the pointers myself to learn.
Thanks
\0after the last significant character of our string.char*pointer is just a pointer to somewhere in RAM. Whether you can consider it a "string" or not is purely a matter of how you deal with it.int*andint[]for a while first, as people don't seem to have the same misconceptions about them.