Skip to content

Commit 2870347

Browse files
authoredNov 20, 2018
Added scanf
scanf(..) is the normal way of parsing integers.
1 parent d2adfb7 commit 2870347

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed
 

‎execlp.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44

55
int main()
66
{
7-
char c, *ptr, *pString[] = {"pwd", "ls", "date", "who"};
7+
char *pString[] = {"pwd", "ls", "date", "who"};
88
int i = 0;
99

1010
printf(" 0 = pwd \n 1 = ls \n 2 = date \n 3 = who \nEnter Number: ");
11-
c = (char) getchar();
12-
i = (int) strtol(&c, &ptr, 10);
11+
scanf("%d", &i);
1312

1413
execlp(pString[i], pString[i], (char *) 0 );
1514
printf("Warning! execlp failed...\n");
1615

1716
return 0;
1817
}
19-

0 commit comments

Comments
 (0)