The idea of the project is to read in 5 strings from a file. Then we need to print the array, then sort the array, then allow the user to search in the array for a strings position number.
Here is what we have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_NUM 25
#define MAX_SIZE 10
void readFile(FILE* fpIn, int num, char arr[][MAX_SIZE]);
void printArr(char arr[][MAX_SIZE], int num);
void bubble(char arr[][MAX_SIZE]);
void interact(char arr[][MAX_SIZE]);
int srch(char arr[][MAX_SIZE], int item);
int main(int argc, char* argv[])
{
printf("Authors: Tyler Tracey and Andrea Boyd");
printf("\nId No. : N00767255 : N00823811");
printf("\nDate : April 20th 2012 @ 8 a.m.");
printf("\nCourse : COP2220\n");
int num = (atoi(argv[2]));
FILE* fpIn;
int i;
char arr[MAX_NUM][MAX_SIZE];
readFile(fpIn, num, arr);
printArr(arr, num);
bubble(arr);
interact(arr);
return 0;
}
void readFile(FILE* fpIn, int num, char arr[][MAX_SIZE])
{
int i;
while((fpIn = fopen("names", "r")) != NULL)
{
for(i = 0; i < num; i++)
{
fscanf(fpIn, "%s", &arr[MAX_NUM][i]);
}
}
fclose(fpIn);
}
void printArr(char arr[MAX_NUM][MAX_SIZE], int num)
{
int i;
for( i = 0; i < num; i++ )
{
printf("%s : %s \n", arr[i][0], arr[i][1] );
}
}
void bubble(char arr[MAX_NUM][MAX_SIZE])
{
}
void interact(char arr[MAX_NUM][MAX_SIZE])
{
int item = 0;
srch(arr, item);
}
int srch(char arr[MAX_NUM][MAX_SIZE], int item)
{
}
The problem is our program is crashing after the initial print of our names so we cannot see if the other things we change are working. Please help ASAP! This is due in about 9 hours!!
We are using a linux-based system to run the file so that cmdline is: ./a.out infile 5