How to create a string-type variable in C

后端 未结 8 1372
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 08:42

Question

How to declare a string variable in C?

Background

In my quest to learn the basics of c, I am trying to port on

8条回答
  •  滥情空心
    2021-02-04 08:56

    The int your putting is not a string, a string looks like "char myString[20]". Not like "int name", that's an integer and not a string or char. This is the code you want:

             int main(int argc, const char * argv[])
    {
    
    char name[9999];
    printf("What is your name?\n");
    scanf("%s", name);
    system("cls");
    printf("Your name is %s", name);
    
    return 0;
    }
    

提交回复
热议问题