Your first error is because you have done:
for (int i = 0; ...
instead of:
int i;
for (i = 0; ...)
(alternatively, you can leave that bit alone and add -std=gnu99
to your gcc options).
Your second error is because the line:
str += " ";
attempts to add two pointer values. That doesn't have any defined semantics in C - it doesn't make any sense. It's not even particularly clear what you're trying to do here - perhaps you want to start with an empty string, then append 10 copies of the string " "
to it? If so, then you need to change it to something like:
char str[100]; /* Allocate space for a 99 character string, plus terminator */
int i;
str[0] = '\0'; /* Start with empty string */
for (i = 0; i < 10; i++)
{
strcat(str, " ");
}
In this particular case though, because you're always looping 10 times you don't really need a loop at all - you can just use a string of 10 spaces:
char str[100];
strcpy(str, " "); /* 10 spaces */
(The str[0] = '\0';
is unnecessary because we're now using strcpy
, not strcat
).