Fixed
|
→ Cheap Animated Banners ←
Fixed
→ Cheap Animated Banners ←
→ Cheap Animated Banners ←
It's definitely something to do with directories then. Where did you place Profile.txt? If its in the root (the folder that has src/ in it, not inside src/), you have to do "./Profile.txt", otherwise it needs to be in the bin folder.
i'm a beginner as well but i'll try my best.
the code given is fine according to your query but i think it's missing some closing braces and a return statement. make sure the .txt file is in the same directory and don't get confused with "file could not be found" and "profile not found". you may get the second one even if the file exists according to your code.
Code:#pragma warning (disable: 4996) #include <stdio.h> #include <stdlib.h> int main() { /*User Struct which is used in order to create a new profile with a name, password, key and potential new files (Created after the login)*/ typedef struct User { char name; char password; char key; char files[]; }; struct User User2; FILE *file; FILE *open = 0; char openFile[100]; int answer = 0, choice = 0, found = 0, i = 0; printf("Hello! Welcome to Final Project\n\n"); while (choice == 0) { printf("Press (1) to login\n"); printf("Press (2) to create a new account\n"); printf("Your choice: "); scanf("%d", &answer); printf("\n"); if (answer == 1) { // Open the file for reading file = fopen("Profile.txt", "r"); if (!file) { printf("File could not be found!\n"); getchar(); getchar(); choice = 0; } //Load File i = 0; while (!feof(file) && !found) { ++i; fscanf(file, "%s\t%s", &User2.name, &User2.password); if (strcmp(&User2.name) == 0 && strcmp(&User2.password) == 0) { printf("Profile found (%d): %s %s\n", i, &User2.name, &User2.password); choice = 1; found = 1; } } if (!found) { printf("Profile not found!\n"); printf("Try again.\n\n\n"); choice = 0; } fclose(file); } } return 0; }
→ Cheap Animated Banners ←
did the above code fix the issue lol.
→ Cheap Animated Banners ←
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |