How to create a string-type variable in C

后端 未结 8 1375
没有蜡笔的小新
没有蜡笔的小新 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 09:06

    In C you can not direct declare a string variable like Java and other language. you'll have to use character array or pointer for declaring strings.

    char a[50];
    printf("Enter your string");
    gets(a);
    

    OR

    char *a;
    printf("Enter your string here");
    gets(a);
    

    OR

    char a[60];
    scanf("%59s",a);
    

提交回复
热议问题