ibadia
ibadia

Reputation: 919

Error while calling a function

On running this program i am getting error [Error] type of formal parameter 1 is incomplete on dev cpp i am calling the function assign through main and i am getting the above mentioned error.

  #include <stdio.h>
void assign(struct username i);
 void show1(struct username i);
struct username
{
  char name[30];
  int rollno;
  float salary;
};
int main(void)
{
    struct username i;
    assign(i);
    show1(i);
} 


void assign(struct username i)
{
    puts("enter name");
    scanf("%s",i.name);

    puts("Enter roll no");
    scanf("%d",i.rollno);

    puts("Enter salary");
    scanf("%f",i.salary);
 }


  void show1(struct username i)
{
   printf("\n---------------------------------\n");
   printf("%s",i.name);
   printf("\n------%d-------\n",i.rollno);
   printf("%f",i.salary);
}

Upvotes: 0

Views: 61

Answers (3)

Stefan Golubović
Stefan Golubović

Reputation: 1275

#include <stdio.h>

struct username {
    char name[30];
    int rollno;
    float salary;
};

void assign(struct username *i);
void show1(struct username *i);

int main(void)
{
    struct username i;
    assign(&i);
    show1(&i);
}

void assign(struct username *i)
{
    puts("enter name");
    scanf("%s", i->name);

    puts("Enter roll no");
    scanf("%d", &i->rollno);

    puts("Enter salary");
    scanf("%f", &i->salary);
}

void show1(struct username *i)
{
    printf("\n---------------------------------\n");
    printf("%s", i->name);
    printf("\n------%d-------\n", i->rollno);
    printf("%f", i->salary);
}

I'm guessing that this is what you wanted. scanf requires pointer to some type and struct is passed by value into the function, so if you want to see the result in main you need to pass it by reference.

Upvotes: 2

jhon
jhon

Reputation: 1

Well, try using another IDE i would recommend like many others will do the code:blocks IDE, because i used dev cpp for a while and sometimes i have problems but when i run the code in another IDE it works just fine. Try struct(username i);

Upvotes: -1

cadaniluk
cadaniluk

Reputation: 15229

You declare a function taking an argument with an, at that time, undeclared type because struct username is introduced into the scope after it's first usage.

Use a forward declaration or exchange the function declarations and the structure definition.

Upvotes: 1

Related Questions