This is for an extra credit assignment for class. Requirements I am having trouble with:
1. User enters number specifying numbers of integers
2. User enters integers
3. program will read them and parse.
----------------------------------------------------------
Here is a sample input and what the program should do:
How many numbers: 5
Enter numbers: 4 66 56 3 2
Here are the numbers:
4
66
56
3
2
----------------------------------------------------------
This program is for storing 2D matrices.
Here is what I have, but I can't get it to store my string of numbers. Without the part where I enter "how many numbers" and the for loop, it works (i.e. it gets the string). With the two additions, it skips to the end after I enter the number of numbers:
#include <stdio.h>
int main()
{
int num;
int i;
char string[256];
printf ("How many different numbers?: ");
scanf("%i", &num);
printf( "Please enter a long string: " );
fgets ( string, 256, stdin );
for ( i = 0; i < 256; i++ )
{
if ( string[i] == '\n' )
{
string[i] = '\0';
break;
}
}
int counter = 0;
char temp[256];
int tempcount = 0;
for (counter = 0;counter<256;counter++)
{
if (string[counter] != " ")
{
temp[tempcount] = string[counter];
tempcount++;
}
else
{
printf("Here is the string, %s\n", temp);
free(temp);
tempcount = 0;
}
}
return 0;
}