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

struct a{
           char *c;
           int b;
           }t;
    

int main()
{
    scanf("%s %d",t.c,&t.b);
    printf("%s",t.c);
    getch();
    return 0 ;
           }

I guess there is some problem in receiving input (more precisely in t.c part). Further assistance will be appreciated.

Recommended Answers

t.c is nothing more than a pointer that has no memory allocated to it. scanf() does NOT allocate the memory for you, you have to do that yourself. Change the structure to something like this and it will work.

struct a
{
   char c[255];
   int b;
};
Jump to Post

All 2 Replies

t.c is nothing more than a pointer that has no memory allocated to it. scanf() does NOT allocate the memory for you, you have to do that yourself. Change the structure to something like this and it will work.

struct a
{
   char c[255];
   int b;
};

t.c is nothing more than a pointer that has no memory allocated to it. scanf() does NOT allocate the memory for you, you have to do that yourself. Change the structure to something like this and it will work.

struct a
{
   char c[255];
   int b;
};

Thank you. I got the concept.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.