Confused About Pointers in C and changing data at memory addresses -



Confused About Pointers in C and changing data at memory addresses -

i think understand concept improve if can assist me in current project i'm working on. want utilize c edit info @ specific memory addresses, using pointers. specifically, have 2 character arrays (strings) need both read info @ specific locations, , write @ specific locations.

i'm confused syntax of pointers, such * , -> , &.

from understanding, * refers info kept @ current memory address of pointer. so, example, if wanted edit info @ origin memory address of char *p, like: (*p) = 'c';

now, if wanted alter character @ 2nd memory address origin of p?

also, understand & refers location of pointer. don't know how utilize syntax.

here example:

int orig_length = strlen(original_string); //-1 \0? char *poriginal, *pnew_string; poriginal = &original_string; while(orig_length>0) { k = 0; j = 0; while(isalpha(*(poriginal+j))) { j++; k++; } while(k > 0) { *(pnew_string+(j-k)) = toupper(*(poriginal+k-1)); //toupper k--; } if(*(poriginal+(j)) == '_') { *(pnew_string+(j)) = ' '; } else { *(pnew_string+(j)) = *(poriginal+(j)); } orig_length = orig_length - j; } *(pnew_string+strlen(pnew_string)) = '\0'; //syn? necessary? ... //program continues...

by way, programme meant take 1 string "now_i_understand!" , reverse each word, capitalize each word, switch _ ' ', , leave other punctuation alone: "won dnatsrednu!"

if dealing array of characters (and is), utilize array syntax:

pnew_string[j+1] = poriginal[j+1];

note syntax equivalent to:

*(pnew_string + j + 1) = *(poriginal + j + 1);

but more readable.

dealing of other cases you've got should obvious given example.

c pointers memory

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -