LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

runtime error with scanf function

Solved!
Go to solution

Hello,

 

I am trying to create a simple console application and keep getting the following run-time error from the CVI compiler:

 

NON-FATAL RUN-TIME ERROR:   "c:\CVI Programs\struct2.c", line 20, col 17, thread id 0x00004D6C:   Parameter type mismatch; expecting pointer to char but found pointer to aggregate or userdefined.

 

It's talking about line 20 in my code. I don't get it, I have had no issues with this using the GCC compiler. Can anyone take a look? below is the code.

 

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

#define NAME_SIZE 40

struct employee
{
 char name[NAME_SIZE];
 char hireDate[15];
 float salary;
};

int main (void){
 
 struct employee hire1 = {"jimmy", "7/2/15" , 105000.00};
 struct employee hire2;

 
 printf("enter the employee's name\n");
 scanf("%s", &hire2.name);
 printf("enter the employee's hire date\n");
 scanf("%s", &hire2.hireDate);
 printf("enter the employee's salary\n");
 scanf("%f", &hire2.salary);
 
 printf("employee 1 info is name:%s, hire date:%d, salary:%f\n", hire1.name, hire1.hireDate, hire1.salary);

 char c = getchar();

 return 0;

}

 

 

0 Kudos
Message 1 of 2
(2,799 Views)
Solution
Accepted by topic author TestEngineer11

You don't have to use the addressing operator ("&") when scanning strings. Your line must look this way:

scanf ("%s", hire2.name);


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 2
(2,784 Views)