From: Maxximo Newsgroups: comp.os.msdos.djgpp Subject: Re: I need help adressing characters in a string Date: Tue, 27 Apr 1999 11:05:57 GMT Organization: Deja News - The Leader in Internet Discussion Lines: 78 Message-ID: <7g45mj$fih$1@nnrp1.dejanews.com> References: <7g439h$dk3$1 AT nnrp1 DOT dejanews DOT com> NNTP-Posting-Host: 138.132.53.11 X-Article-Creation-Date: Tue Apr 27 11:05:57 1999 GMT X-Http-User-Agent: Mozilla/3.04Gold (X11; I; OSF1 V4.0 alpha) X-Http-Proxy: 1.0 x11.dejanews.com:80 (Squid/1.1.22) for client 138.132.53.11 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com > Well, consider this : > > char *string; > > void main (void) > { > int i; > for (i=; i=lengthof(string); i++) > { > dosomething with string[i]; > } > > I can't do that, the compiler gives me an error. > > How should I declare the string? > First of all: you have a real string or a pointer to it? If you referred a string declared somewhere in your code, you must declare: extern char *string; or extern char string[]; If you only declare: char *string; you have declared a pointer, but you must initialize it with the address of a string. Then, first declare your string: char my_string[20]; or declare and initialize it: char my_string[] = "hello, World"; Remember: the string is terminated with a character '\0'. You must provide space for this in your declaration. If you want, you can declare a pointer to it: char *string; and initialize it with: string = my_string; or (it is the same): string = &my_string[0]; Look this: char string[] = "Hello, World!" main() { char *pointer; int i; for(i=0; i