Is this Correct?
May 9, 2011 at 2:23am UTC
im using a subprogram is this the correct usage of void..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include <conio.h>
#include <stdio.h>
#include <string.h>
void getEmpDetails(char *empID){
FILE *empt;
char employeeID[50];
char empname[50];
char salLevel[50];
char *comString;
while (!feof(empt)){
fgets (comString,sizeof (comString),empt);
if (strstr(comString,rString)){
printf ("Emp Name: %s\nEmp ID: %s\nEmp Sal Lvl: %s" ,empname,employeeID,salLevel);
break ;
} else {
printf("Emp Not Found" );
return 1;
}
}
}
main(){
clrscr();
char empID[50];
printf("Enter Emp ID: " )
scanf("%s" ,empID);
getEmpDetails(empID);
getch();
return 0;
}
May 9, 2011 at 2:30am UTC
a void function cant return a value, so no. you must delete the
and it will work
May 9, 2011 at 2:33am UTC
Rather, change it to simply return; if you actually want to return from the function (which I assume you do).
May 9, 2011 at 3:05am UTC
well its good practice to add that, but otherwise it will return automatically at the end of the function.
May 9, 2011 at 3:05am UTC
so when i enter emp id in the main..
it can get by the void..?
May 9, 2011 at 8:34am UTC
The function is not returning the emp id/details. Your function is just printing the details, which it will continue to do irrespective of the return type. If the return type is void then:
return ;
is a good practice.
Topic archived. No new replies allowed.