I need to fill an array with a string that is input by a user. For example user enters such string like these: "St/80" We know the length before user enters it btw. I wanna do this:
array[0]='S';
array[1]='t';
array[2]='/';
array[3]=8;
array[4]=0;
#include <stdio.h>
int main(void)
{
char arr[10];
scanf("%9s", arr);
printf("%s",arr);
return 0;
}
here if your input string is "St/80" then it will assign as below:
array[0]='S';
array[1]='t';
array[2]='/';
array[3]=8;
array[4]=0;
also you can increase the size of string by increasing the index of arr.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.