+ 1

Why is this C program crashing?

#include<stdio.h> #include<string.h> int main() { char n[5],a[5][10]; printf("Enter a 5 digit number: "); gets(n); int i; for(i=0;n[i]!='\0';i++) { if(n[i]=='1') strcpy(a[i]," #\n##\n #\n #\n #\n #\n #\n###"); if(n[i]=='2') strcpy(a[i],"#####\n #\n #\n #\n#####\n#\n#\n#####"); if(n[i]=='3') strcpy(a[i],"#####\n #\n #\n#####\n #\n #\n #\n#####"); if(n[i]=='4') strcpy(a[i],"#\n#\n#\n# #\n#####\n #\n #\n #"); if(n[i]=='5') strcpy(a[i],"#####\n#\n#\n#####\n #\n #\n #\n#####"); } for(i=0;i<5;i++) printf("%s",a[i]); return 0; } it is program to show numbers in #. it is giving runtime error. pls help me troubleshoot.

17th Nov 2017, 12:20 AM
Shantanu Shinde
Shantanu Shinde - avatar
2 odpowiedzi
0
that helped. thanks. I also want to know how can I make them print side by side.
17th Nov 2017, 4:25 AM
Shantanu Shinde
Shantanu Shinde - avatar