-2

I tried with the following code:

    #include<stdio.h>
    int main()
    {
    char *a;
    scanf("%s",a);
    printf("%s",a);
    return 0;
    }

I can enter a string but nothing is printed in the screen.

tkr karthikeyan
  • 43
  • 1
  • 12
  • 2
    There are millions of examples of how to do this. Please, learn to do a little bit of research for yourself. – Jonathon Reinhart Jan 03 '14 at 06:27
  • 2
    Well that looks like a seg-fault waiting to happen. – PakkuDon Jan 03 '14 at 06:27
  • 2
    Look at this question and answer: http://stackoverflow.com/questions/16983174/whats-wrong-with-this-scanf – Phillip Kinkade Jan 03 '14 at 06:28
  • possible duplicate of [making use of string pointer to print the character-integer combinations](http://stackoverflow.com/questions/4484376/making-use-of-string-pointer-to-print-the-character-integer-combinations) – Hamad Jan 03 '14 at 06:51

2 Answers2

0

By allocating some memory before using it.

char *a;
a=malloc(sizeof(char)*10);
scanf("%s",a);
printf("%s",a);
return 0;
Digital_Reality
  • 4,488
  • 1
  • 29
  • 31
0
char *a = (char *) malloc(512 * sizeof(char));

c is rigorous you should do all the preliminary work

  • Elaborate more on what this does and why it's necessary. As it stands, it's unclear to the OP why this could help. – arne Jan 03 '14 at 06:58