-
pointer and strings
how do you use pointers to point at individual elements of a string. Because i want to have a pointer (*p) pointing at the first element of the string strng[0], and a second pointer (*q) pointing at the last element of the string.
say if the string was "go dog"
(which is a palindromes..which spells the same string foward and backward,,,,thats why i need help on this part of the project)
can anybody help?
-
char buffer[50] = "go dog";
char *front, *back;
front = buffer;
back = buffer[strlen(buffer)-1]; // or "buffer + (strlen(buffer)-1)"
Quzah.
-
for the pointer (back) it said there was an errror and that it cannot convert from char to char*.
-
TRY
front = buffer;
*back = buffer[strlen(buffer)-1]; // or "buffer + (strlen(buffer)-1)"
-
ok that second one works... but when i try to print the first element it prints the entire string and i try to print the second element all it prints is 'e' all the time. I need to only print the first element and the last element because i have to be able to compare the elements to see if they are the same.. I am working on this homework assignment which tells us test if the string is a palindrome...(ex. "go dog" because its the same sentence read backwards)...so my plan is to check if the first element is same as last and then i will.....(first++, and last--) until the string has reached the middle and the program has tested it.
-
You could just say "The dog ate your homework"
-
to brian
a Brian why dont u shut your ass up .... your not helping
-
lostpoet ... relax man ... that was funny :)
-
Well, gee, I'm sorry, but I am fed up of worthless little craps posting crappy annoying paladrome questions.