My goal is to scroll through a predefined set of lines when printing each of them on a separate line without using a counter variable. The lines I commented on are working code, but a counter is required. The four lines beneath it surpassed me.
int main(int argc,char* argv[]){ char *astring[500]; astring[0]=(char*)"ABC"; astring[1]=(char*)"DEF"; astring[2]=(char*)"GHI"; astring[3]=(char*)NULL;
I tried the following options without success.
This code:
char *p=*astring; while (*p++){ printf("%s\n",*p); }
It compiles normally, but after execution, a segmentation error occurs, and the program immediately exits from it.
I tried:
while (**p++){ printf("%s\n",*p); }
and the program will not compile due to invalid type argument of 'unary *' .
Then I changed char *p=*astring; on char *p=astring; and got a warning initialization from incompatible pointer type
Then I also tried char *p=**astring; and received this warning for the compiler: initialization makes pointer from integer without a cast
Should I be confused with the stars or is this what I'm trying to make impossible? Anyone have a solution?
source share