I'm trying to read in text from a file exclusive or it against a random number, and output that to another file. I thought this should work, but it seg faults as soon as I run my program. Any help would be great thanks.
Code:/*Implement a stream cipher*/ #include <stdio.h> #include <stdlib.h> #include <getopt.h> int main(int argc, char *argv[]) { /*Declare Variables*/ int randNum; int seed; int s; int i = 0; char stream[131]; char fileName1[11]; char fileName2[11]; /*opening files*/ FILE *infp; FILE *outfp; infp = fopen(argv[1], "r"); outfp = fopen(argv[2], "rw"); /*Test to ensure both files opened successfully*/ if(!infp) printf("File could not be opened "); else if(!outfp) printf("File could not be opened "); /*set seed value*/ seed = atoi(argv[3]); srand(seed); stream[i] = fgetc(infp); ++i; printf (" line 91 \n "); /*atoi converts to integer*/ for (i; (stream[i] != EOF); ++i) { s = atoi(stream[i]); /*line 95*/ s = s ^ rand(); putc(s, outfp); stream[i] = fgetc(infp); } /*close the files*/ fclose(infp); fclose(outfp); return 0; }



LinkBack URL
About LinkBacks


