Hi all, my name is attreme and I'm learning to program as an aeronautical engineer.
This was supposed to be a simple program that would read four strings and then print only the ones that started witht the letter "b." When I run the program, I don't get any error messages, but the program immediatly exits with 0. I believe that my problem is in the string "si." I wanted it to change the string from s1 to s2 and so forth, but I think it's just not reading. Please help.
Code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main() {
char s1[5] = "abcd", s2[5] = "bcde", s3[5] = "bdef", s4[5] = "defg";
int i;
char sj[5] = "aaaa";
char si[5];
for (i = 0; i <=4; i++){
strcpy (sj, si);
if ((strncmp (sj, s2, 1)) == 0){
printf ("%s", sj);
}
}
return 0;
}
Thanks all.