Here is my problem. Immediately after I type in some input and hit enter the program executes. And I some how figured out that the problem was due to the for loop which I was using. Here is the code.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main(){
char myString[100];
char myChar = myString[6];
int i;
for(i=0; i<=100; i++){
scanf("%s", myString[i]);
}
printf("%c\n", myChar);
system("pause");
}
You are attempting to read 101 strings
%s, but you allocated space for 100 characters. You pass a character instead of a character pointer toscanf, causing a crash.If you are trying to read 100 characters, you should pass
%cin the format line, and an address in the parameter part ofscanfcall:You should also either replace
<=with<, or allocatemyString[101].If you are looking to get one string, call
scanfonce, not in a loop:You are also reading the 6-th character before you place any data into the character array. That value is not going to change after the
forloop.