Hi all,
I am on my yearly try to learn how to code in C once again
Got further than usually this time =)
Anyway, I was wondering how to modify individual charactes in a string.
Say I have the following code:
This works fine. But this:
Gives me a segmentation fault. Why is that? Also, since apparently direct access to the chars does not work, how can I modify individual chars in the string?
If this is completely ridiculous please enlighten me why so
I am on my yearly try to learn how to code in C once again
Anyway, I was wondering how to modify individual charactes in a string.
Say I have the following code:
Code:
#include <stdio.h>
int main(int argc, char *argv[])
{
char abc[20];
strcpy(abc, "Wahoo!\0");
printf("%s", abc);
return 0;
}
Code:
#include <stdio.h>
int main(int argc, char *argv[])
{
char abc[20];
strcpy(abc, "Wahoo!\0");
printf("%s", abc);
printf("%s", abc[1]);
return 0;
}
Gives me a segmentation fault. Why is that? Also, since apparently direct access to the chars does not work, how can I modify individual chars in the string?
If this is completely ridiculous please enlighten me why so