result: error!Code:char *name[4]; int i = 0; while ( i < 4) { int k = 0; while (k < 4) { *(name[i]+k) = 'c'; k++; } i++; }
why?
result: error!Code:char *name[4]; int i = 0; while ( i < 4) { int k = 0; while (k < 4) { *(name[i]+k) = 'c'; k++; } i++; }
why?
Last edited by zcrself; 08-17-2009 at 01:53 AM.
Because name[4] is out of bounds.
You might want to look-up what i++ and k++ actually mean.
More specifically, what the Boolean expression (i++ < 4) means...
Code:int i = 3; if(i++ < 4) printf("I solved my own question\n");
Not sure what you are trying to do but the code is attempting to insert values at name[4] which is outside the array index
[edit: Beaten to the punch by zacs7]
Last edited by strider1974; 08-17-2009 at 01:51 AM.
Code:char *name[4][4]; int i = 0; while ( i < 4) { int k = 0; while (k < 4) { *(name[i]+k) = 'c'; k++; }
i++;
}
//now u r code is oky.....u r using one dimention pointer array but u using two loop nested it not work....
using two dimention then try.....
HOPE YOU UNDERSTAND.......
By associating with wise people you will become wise yourself
It's fine to celebrate success but it is more important to heed the lessons of failure
We've got to put a lot of money into changing behavior
PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
IDE- Microsoft Visual Studio 2008 Express Edition
Everyone? I only see one poster that attempted to modify the original code (karimmughal's post). Everyone else simply pointed out the 2 mains issues with the code.Everyone who posted and modified the original in the beginning needs to take a crash course in C strings.
bit∙hub [bit-huhb] n. A source and destination for information.
The only problem I see from the original is that there was no storage allocated for name strings. There was never any bounds issue.