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?
Printable View
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?
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]
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.....
Everyone who posted and modified the original in the beginning needs to take a crash course in C strings.
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.Quote:
Everyone who posted and modified the original in the beginning needs to take a crash course in C strings.
Everyone who modified it, yes. I see that there is only one aside from the OP, so that's a total of two who needs to take a crash course.
The only problem I see from the original is that there was no storage allocated for name strings. There was never any bounds issue.