I need to do something like the following:
int main(void) {
char a,b,cstring;
printf(\"please enter something\");
scanf(\"%c %c\",&a,&b);
prinf(\"th
That's undefined behaviour. Your cstring variable, despite its name, is a single character, and you are attempting to read up to 35 characters into what its current value points to. In other words, the current character in cstring will be converted into a pointer and it will try to write your input there. That's going to be a memory location (most likely) between 0 and 255 inclusive.
That's what's causing your segmentation violation. Start with something like this instead:
#include
int main(void) {
char a,b,cstring[99];
printf("please enter something");
scanf("%c %c",&a,&b);
printf("thanks, now some more");
fgets(cstring,35,stdin);
return 0;
}
Or, possibly better:
#include
int main(void) {
char a,b,cstring[99];
printf("please enter something");
fgets(cstring,35,stdin);
sscanf(cstring,"%c %c",&a,&b);
printf("thanks, now some more");
fgets(cstring,35,stdin);
return 0;
}
Or, if you want a more robust solution for user input, see here. It's a tried and tested method with very good error checking.