-3

i want to get a string from the keyboard ,like "abcde" , and then insert it in a char,for example b which is char , but there is no function,like atoi(a) for integers.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    char a[6];
    char b;
    scanf("%s",a);
    printf("%s",a);
    printf("\n");
    b=a;
    printf("%c",b);

    return 0;
}

1 Answers1

1

You cannot insert a string into a char. You can, however, convert the string to an array of chars. If this is what you are looking for, please see this answer

Community
  • 1
  • 1
Aaron P
  • 31
  • 4