-
fix this code
The user need to type largest (3,7,11,9) at the prompt. It means that I have 3 numbers in the array and I need to find the largest integer in the array containing 7, 11, 9.
I was able to get the program to read 3 as teh size of the array but how can I instruct the program to put the 7, 11, 9 in the array??
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char *nargs;
int num[sizeof nargs];
int largestsofar = 0;
int i;
if (argc==2)
{
nargs=malloc(strlen(argv[1]+1));
strcpy (nargs, argv[1]);
}
for(i=0;i<sizeof(nargs)/sizeof(char);i++)
{
if (largestsofar < num[i])
largestsofar = num[i];
}
printf("The largest integer is: %d\n",largestsofar);
printf("%d",nargs);
free(nargs);
return 0;
}
-
thanks for the help.....but what if I want the user to type parenthesis like largest (4,5,6,7,9)
your code get rids of the commas. I tried to get rid of the () but it does not seem to work, I was trying to add && || to the code!!