C program to read a string by using gets function
#include<stdio.h> #include<string.h> main() { char str1[100]; char str2[100]; printf("enter a string\n"); gets(str1); printf("str1=%s\t str2=%s\n",str1,str2); strcpy(str2,str1); str2[9]='\0'; printf("str1=%s\t str2=%s\n",str1,str2); }OutPut:
madan@madan-Lenovo-G570:~/madan$ cc array19.c array19.c: In function ‘main’: array19.c:9:1: warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations] gets(str1); ^ /tmp/ccm6ljlv.o: In function `main': array19.c:(.text+0x2f): warning: the `gets' function is dangerous and should not be used. madan@madan-Lenovo-G570:~/madan$ ./a.out enter a string welcome str1=welcome str2= @-� str1=welcome str2=welcome