Hi, Im having trouble debugging my program.
My program is suppose to read a txt list that consists of a number followed by letters
82
fsdfkd
0
fdsfds
I got that part to work thanks to some help, but now i got a problem when i try to call it into the main function
I know it looks crappy but i dont know how to call seperate elements from one function so im just going to do two seperate function with them returning one value each...Code:#include <stdio.h> #include <string.h> #include <stdlib.h> #define MAX 100 #define SOURCE2 "pattern2.txt" #define SOURCE3 "fp2.txt" struct patterninput { int mismatches; char thepattern[MAX]; }; int main(void) { int returns_mismatches(int array_num); char returns_pattern(int array_num); int array_num; printf("enter the number for the array \n"); scanf(" %d ", &array_num); printf("mis: %d", returns_mismatches(array_num)); printf("pat: %s", returns_pattern(array_num)); return 0; } int returns_mismatches(int array_num) { struct patterninput lines[MAX]; char temp[MAX]; char *p; int k=0; FILE *fp = fopen(SOURCE2, "r"); FILE *fp2 = fopen(SOURCE3, "w"); while (fgets(temp, MAX, fp) != NULL) { if ((p = strchr(temp, '\n')) != NULL) { lines[k].mismatches = atoi(temp); *p = '\0'; if (fgets(lines[k].thepattern, MAX, fp ) != NULL ) fprintf(fp2,"%d %s", lines[k].mismatches, lines [k].thepattern); } if(k == array_num) return(lines[k].mismatches); k++; } fclose(fp); fclose(fp2); } char returns_pattern(int array_num) { struct patterninput lines[MAX]; char temp[MAX]; char *p; int k=0; FILE *fp = fopen(SOURCE2, "r"); FILE *fp2 = fopen(SOURCE3, "w"); while (fgets(temp, MAX, fp) != NULL) { if ((p = strchr(temp, '\n')) != NULL) { lines[k].mismatches = atoi(temp); *p = '\0'; if (fgets(lines[k].thepattern, MAX, fp ) != NULL ) fprintf(fp2,"%d %s", lines[k].mismatches, lines[k].thepattern); } if(k == array_num) return(lines[k].thepattern); k++; } fclose(fp); fclose(fp2); }
If this program works, it should ask user for a number, and then print the corresponding number and pattern....
the problem im getting is in the compiling again
this line near the end:
gives me these compile errorsCode:return(lines[k].thepattern);
warning: return makes integer from pointer without a cast
warning: function returns address of local variable
thanks for any help!



LinkBack URL
About LinkBacks
thanks for any help! 


