Is this Correct?

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;
}
a void function cant return a value, so no. you must delete the
 
return 1

and it will work
Rather, change it to simply return; if you actually want to return from the function (which I assume you do).
well its good practice to add that, but otherwise it will return automatically at the end of the function.
so when i enter emp id in the main..

it can get by the void..?
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.