#include #include #include #include #include #include #include #include using namespace std; char *substring(size_t start, size_t finish, const char *src, char *merge, size_t size) { int count = finish - start; if ( count >= --size ) { count = size; } sprintf(merge, "%.*s", count, src + start); return merge; } int main() { char c[20] = " "; /* declare a char array */ char c2[20]= " "; /* declare a char array */ FILE *file, *file2, *file3; /* declare a FILE pointers */ file = fopen("username.txt", "r"); file2 = fopen("password.txt", "r"); file3 = fopen("usernamesPasswords.txt", "w"); /* open a text file for reading */ if(file==NULL) { printf("Error: can't open username file. "); return 1; } else if(file2==NULL) { printf("Error: can't open password file. "); return 1; } else if(file3==NULL) { printf("Error: can't open usernamesPasswords file. "); return 1; } else { char * p; while(fgets(c2, 200, file2) != NULL && fgets(c, 200, file) != NULL) { /* keep looping until NULL pointer... */ p = strchr(c, ' '); if (p) { *p = '\0'; } p = strchr(c2, ' '); if (p) { *p = '\0'; } fprintf(file3, "%s %s ",c, c2); } char choice,ch; printf("File Username Merged With File Password... "); printf("Do You Want to Display File Contents "); scanf("%c",&choice); fseek(file3, 0, SEEK_SET); // Set the file pointer to start of file printf("The Contents of usernamePasswords file is "); if (choice == 'Y' || choice == 'y') { file3 = fopen("usernamesPasswords.txt", "r"); while(1) { ch = fgetc(file3); if( feof(file3) ) { break; } printf("%c", ch); }
} else { printf("Program Closing "); }
fclose(file); fclose(file2); fclose(file3); return 0; } }
Can anyone correct this program i cannt run it