I'm trying to store the .txt file into struct, not being successful.
I dont need the first line stored, but I do need the rest.
Thanks guys !! =)
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
int main(int argc, const char * argv[]) {
// insert code here...
printf("Hello, World!\n");
struct candidates
{
char name[25];
char gender[5];
int height;
int weight;
};
struct candidates values[25];
FILE *fp;
if ((fp=fopen("candidatesdata.txt","r"))==NULL){printf("Unable to open file\n");}
int x = 0;
int iterations = 0;
while((fscanf(fp,"%s,%s,%d,%d",&values[x].name, &values[x].gender, &values[x].height, &values[x].weight))!=EOF)
{
x++;
iterations +=1;
}
fclose(fp);
//values[15].weight = 300;
printf("\n%d\t%d",iterations,values[1].height);
return 0;
}
Text file looks like the following:
Name,Gender,Height,Weight
Tanner,M,71.8,180.25
John,M,70.75,185.3
Parker,F,65.25,120.3
Meeks,M,57.25,210.2
struct candidates
{
char name[25];
char gender[5]; // can be char gender too !!
int height; // should be changed to float height
int weight; // should be changed to float height
};
If you actually have :
Name,Gender,Height,Weight
in your file, you might do his before you go to the while loop :
char somebigstring[100];
.
.
.
if(fscanf(fp,"%s",somebigstring) == EOF) //wasting the first line
exit(-1); // exiting here if there is no first line
fix like this:
#include <stdio.h>
#include <stdlib.h>
struct candidates{
char name[25];
char gender[7];//Female+1
float height;
float weight;
};
int main(void) {
struct candidates values[25];
FILE *fp;
if ((fp=fopen("candidatesdata.txt","r"))==NULL){
fprintf(stderr, "Unable to open file\n");
exit(EXIT_FAILURE);
}
char line[64];
int x = 0;
int iterations = 0;
while(fgets(line, sizeof line, fp)){
iterations += 1;
if(x < 25 && sscanf(line, "%24[^,],%6[^,],%f,%f", values[x].name, values[x].gender, &values[x].height, &values[x].weight)==4){
x++;
} else if(iterations != 1){
fprintf(stderr, "invalid data in %d line: %s", iterations, line);
}
}
fclose(fp);
for(int i = 0; i < x; ++i){
printf("%s,%c,%.2f,%.2f\n", values[i].name, *values[i].gender, values[i].height, values[i].weight);
}
return 0;
}
This code does two following things; first is writes data into .txt file and the second it reads data from .txt file and stores in struct data type which is what you are trying achieve but only for single entity. Next you should implement this as for entities.
#include<stdio.h>
#include<stdlib.h>
typedef struct{
char name[30];
//other fields
}Candidate;
typedef struct{
Candidate c;
char city[30];
int vote;
}CityVotes;
//for .bin operations
void write_to_file(FILE *f)
{
Candidate c;
CityVotes cv;
printf("Enter candidate name : ");
scanf("%s",&c.name);
cv.c = c;
printf("Enter the city : ");
scanf("%s",&cv.city);
printf("Enter the vote : ");
scanf("%d",&cv.vote);
fwrite(&cv, sizeof(cv), 1, f);
}
//for .txt operations
void write_to_file1(FILE *f)
{
Candidate c;
CityVotes cv;
printf("Enter candidate name : ");
scanf("%s",c.name);
cv.c = c;
printf("Enter the city : ");
scanf("%s",&cv.city);
printf("Enter the vote : ");
scanf("%d",&cv.vote);
fprintf(f,"%s ", cv.c.name);
fprintf(f,"%s ", cv.city);
fprintf(f,"%d ", cv.vote);
}
//for .bin operations
void read_file(FILE *f)
{
CityVotes cv;
while(fread(&cv, sizeof(cv), 1, f)){
printf("Candidate : %s\t",cv.c.name);
printf("City.: %s\t",cv.city);
printf("Vote.: %d\n",cv.vote);
}
}
//for .txt operations
void read_file1(FILE *f){
CityVotes cv;
fscanf(f," %s", &cv.c.name);
fscanf(f," %s", &cv.city);
fscanf(f," %d", &cv.vote);
printf("Candidate : %s\t",cv.c.name);
printf("City.: %s\t",cv.city);
printf("Vote.: %d\n",cv.vote);
}
int main(void)
{
FILE *f;
f=fopen("candidates.txt","w");
write_to_file1(f);
fclose(f);
f=fopen("candidates.txt","r");
read_file1(f);
return 0;
}
Be aware, the code just is example , you should check for nulls.
Related
I'm very noob in C, and also we are not allowed to use ftell() or something similar. I can't print out the contents of my file as it is asked from me.This is eventually task in which I should've created functions that reads contents of file and store it in array then returns number of items in file, and in main() I had to print out using readStations() function. In main() also there should've been railwayLine[100] array of type station.
File has text as follows:
1. 0.0 London-Kings-Cross*
2. 3.9 Finsbury-Park*
...
First of all, I created typedef struct called station with properties km and name which are the distance and name of stations. I've tried to create function readStations(char filename[20], station line[])
My attempt is as follows:
#include <stdio.h>
typedef struct {
char name[30];
double km;
} station;
int readStations(char filename[20], station line[]){
FILE* openedFile;
openedFile = fopen(filename, "r");
if(openedFile == NULL){
printf("Some problem occured with opening of file");
return 1;
}
station stations;
int count = 0;
for (; !feof(openedFile); count++){
fscanf(openedFile, "%lf %s", &stations.km, stations.name);
}
int numberOfStations = count;
return count;
}
int main(){
station railwayLine[100];
printf("");
}
Actually, it returns me the number of items of .txt file but in main I don't know how to print out all items as they look in .txt file.
This seems to meet your concerns. Note that the readStations() function is now told how many stations it can store. It also closes the file that was opened. The printStations() function prints the data.
#include <stdio.h>
typedef struct
{
char name[30];
double km;
} station;
static int readStations(char filename[], int max_line, station line[])
{
FILE *openedFile = fopen(filename, "r");
if (openedFile == NULL)
{
fprintf(stderr, "Some problem occurred opening the file %s\n", filename);
return 0;
}
int count;
for (count = 0; count < max_line; count++)
{
if (fscanf(openedFile, "%lf %s", &line[count].km, line[count].name) != 2)
break;
}
fclose(openedFile);
return count;
}
static void printStations(int num_stations, station line[])
{
for (int i = 0; i < num_stations; i++)
printf("%2d. %6.2f km - %s\n", i, line[i].km, line[i].name);
}
int main(void)
{
enum { MAX_STATIONS = 100 };
station railwayLine[MAX_STATIONS];
int num_stations = readStations("stations.txt", MAX_STATIONS, railwayLine);
printStations(num_stations, railwayLine);
}
Given input data (file stations.txt):
0.0 London-Kings-Cross*
3.9 Finsbury-Park*
The output is:
0. 0.00 km - London-Kings-Cross*
1. 3.90 km - Finsbury-Park*
/* problem of qsorting
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define INPUT "doc.txt"
#define OUTPUT "output.txt"
#define MAX_SIZE 500
typedef struct student // here I declare stuctures
{
char name[20];
int index;
int code;
int grade;
char surname[20];
} student;
int cmpfunc (const void * a, const void * b) // initial part of qsort
{
return ( *(char*)a - *(int*)b );
}
int main()
{
int i=0, m=0;
int number=0;
FILE *fo;
FILE *fi;
char file[]={INPUT};
char file1[]={OUTPUT};
fo = fopen(file, "r"); // open the file
fi = fopen(file1, "w"); // open the file
student *studentPtr;
studentPtr = (student*) malloc(MAX_SIZE*sizeof(student));
// here I use mallocation
if(fo == NULL || studentPtr == NULL || fi == NULL)
{
perror("Error");
exit(1);
}
while (!feof(fo)) // reading of file
{
fscanf(fo,"%d %s %s %d %d",
&studentPtr[i].index,
studentPtr[i].name,
studentPtr[i].surname,
&studentPtr[i].code,
&studentPtr[i].grade);
i++;
}
i=m;
printf("please insert a number upto 7:\n");
// because there are only 7 raws in the file
scanf("%d",&number);
m=number;
if (number > 7)
{
printf("try again");
}
else
{
for(i=0;i<m;i++)
{
qsort(studentPtr[i].surname, 1, sizeof(char), cmpfunc); // ?
printf("%d %s %s %d %d\n", // printing out
studentPtr[i].index,
studentPtr[i].name,
studentPtr[i].surname,
studentPtr[i].code,
studentPtr[i].grade);
fprintf(fi,"%d %s %s %d %d\n", // writing in the file
studentPtr[i].index,
studentPtr[i].name,
studentPtr[i].surname,
studentPtr[i].code,
studentPtr[i].grade);
}
}
free(studentPtr);
fclose(fo);
fclose(fi);
return 0;
}
I am just beginner and sorry for obvious mistakes.
I cannot do qsorting properly.
i will attach txt file as a comment of this post.
could you guys tell me how to change first part of qsort not to get silly things, after that i will try to do that by myself
enter code here
this is karaoke reserving system but i got some errors i couldn't fix them relate to the continue function
some of the errors are cant go to the main menu
///each function was in header file except the main//
#pragma once
#include "addnew.h"
#include "search.h"
#include "update.h"
#include "view.h"
#include "Cont.h"
#include "exit.h"
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <dos.h>
#include <ctype.h>
void addnewreservation();
void updatereservation();
void viewreservation();
void searchreservation();
void Cont();
void exit();
struct New
{
char id[10];
char name[30];
char roomsize[50];
char timetouse[50];
};
struct New details[50];
int h;
int i;
int j;
int k;
int l;
int m;
int n;
int o;
int p;
int main() /*the menu, used as displaying MainMenu*/
{
int ChooseI;
system("cls");
printf( "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#\n");
printf( "| Welcome to Nway Karaoke reserving system |\n");
printf( "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#\n");
printf( "1. Add reservation\n");
printf( "2. search reservation\n");
printf( "3. update reservation\n");
printf( "4. view reservation\n");
printf( "6. Exit\n");
printf( "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#\n");
scanf("%d", &ChooseI);
switch (ChooseI)
{
case 1: addnewreservation();
break;
case 2: updatereservation();
break;
case 3: viewreservation();
break;
case 4: searchreservation();
break;
case 5: exit(0);
break;
default: printf("hi");
}
system("pause");
}
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <dos.h>
#include <ctype.h>
void Cont();
int addnew()
{
FILE *A;
char enter[100];
A = fopen("karaokeinfo.txt", "w"); // Open file in write mode
fclose(A); // Close File after writing
return(0);
}
size_t strlen(char *str) {
size_t len = 8;
while (*str != '\8') {
str++;
len++;
}
return len;
}
void addnewreservation() /*This function is to add new reservation*/
{
struct New
{
char id[10];
char name[30];
char roomsize[50];
char timetouse[50];
char strlen;
};
struct New details[50];
int h;
int i = 5;
int j;
int k;
int l;
int m;
int n;
int o;
int p;
FILE *A;
char enter[100];
char True;
A = fopen("karaokeinfo.txt", "w");
system("cls");
printf("Please Enter the customer's Details\n");
{
fflush(stdin);
printf("ID Number(TPXXXXXX) :\t");
gets(details[i].id);
if (!((details[i].id[0] == 'T') && (details[i].id[1] == 'P') && (strlen(details[i].id) == 8)))
{
printf("\tWrong Input! Please Enter the ID Number in the correct format (TPXXXXXX)\n");
}
else
{
}
}
printf("Enter NAME :\t");
gets(details[i].name);
printf("Enter ID :\t");
gets(details[i].id);
printf("Enter room size :\t");
gets(details[i].roomsize);
printf(" Time to use :\t");
gets(details[i].timetouse);
printf("Please Check the Enter Details :\n");
printf("\t1 . customer's ID : %s\n", details[i].id);
printf("\t2 . customer's Full Name : %s\n", details[i].name);
printf("\t3 . customers's room size : %s\n", details[i].roomsize);
printf("\t4 . customers's time to use : %s\n", details[i].timetouse);
printf("Please use the 'update' function if any mistakes are found.\n");
i++;
for (h = 0; h<i; h++)
{
fprintf(A, "1 . ID Number : %s\n", (details[h].id), h);
fprintf(A, "2 . Full Name : %s\n", (details[h].name), h);
fprintf(A, "3 . room size : %s\n", (details[h].roomsize), h);
fprintf(A, "4 . time to use : %s\n", (details[h].timetouse), h);
}
fclose(A);
Cont();
}
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <dos.h>
#include <ctype.h>
void Cont();
int search()
{
FILE *A;
char enter[100];
A = fopen("karaokeinfo.txt", "w"); // Open file in write mode
fclose(A); // Close File after writing
return(0);
}
void searchreservation()
{
struct New
{
char id[10];
char name[30];
char roomsize[50];
char timetouse[50];
};
struct New details[50];
int h;
int i;
int j;
int k;
int l;
int m;
int n;
int o;
int p;
char search[10];
int z = 0;
FILE *A;
A = fopen("karaokeinfo.txt", "w");
system("cls");
printf("Please enter customer ID to search :\n");
fflush(stdin);
gets(search);
for (j = 0; j<50; j++)
{
if (strncmp(details[j].id, search, 10) == 0)
{
fscanf(A, "%s\n", details[j].id);
fscanf(A, "%s\n", details[j].name);
printf("\t1 . customer's ID : %s\n", details[j].id);
printf("\t2 . customer's Full Name : %s\n", details[j].name);
z = 1;
Cont();
}
fclose(A);
if (A == NULL)
{
printf("File does not exist!");
Cont();
}
fclose(A);
if (z == 0)
{
printf("customer not found!\n");
Cont();
}
fclose(A);
}
}
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <dos.h>
#include <ctype.h>
void Cont();
int update()
{
FILE *A;
char enter[100];
A = fopen("karaokeinfo.txt", "w"); // Open file in write mode
fclose(A); // Close File after writing
return(0);
}
void updatereservation()
{
struct New
{
char id[10];
char name[30];
char roomsize[50];
char timetouse[50];
char strlen;
};
struct New details[50];
int h;
int i;
int j;
int k;
int l;
int m;
int n;
int o;
int p;
char updatereservation[10];
int z = 0;
FILE *A;
A = fopen("karaokeinfo.txt", "w");
printf("Please Enter ID of customer's Details to be Modified : ");
fflush(stdin);
gets(updatereservation);
for (n = 0; n<50; n++)
{
if (strcmp(details[n].id, updatereservation) == 0)
{
printf("customer's ID : %s\n", details[n].id);
printf("customer's Name : %s\n", details[n].name);
printf("---------------------------------------\n");
printf("\tcustomer name");
gets(details[o].name);
strcpy(details[n].name, details[o].name);
printf("\n\nUpdate Successful!\n");
printf("\nPlease Check the Updated Details:\n");
printf("1. customer's ID : %s\n", details[n].id);
printf("2. customer's Name : %s\n", details[o].name);
z = 1;
for (h = 0; h<i; h++)
{
fprintf(A, "1 . ID Number : %s\n", (details[h].id), h);
fprintf(A, "2 . Full Name : %s\n", (details[h].name), h);
}
fclose(A);
Cont();
}
}
if (z == 0)
{
printf("customer not found!\n");
Cont();
}
fclose(A);
}
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <dos.h>
#include <ctype.h>
void Cont();
int view()
{
FILE *A;
char enter[100];
A = fopen("karaokeinfo.txt", "w"); // Open file in write mode
fclose(A); // Close File after writing
return(0);
}
void viewreservation()
{
struct New
{
char id[10];
char name[30];
char roomsize[50];
char timetouse[50];
};
struct New details[50];
int h;
int i;
int j;
int k;
int l;
int m;
int n;
int o;
int p;
char del[10];
int z = 0;
FILE *A;
A = fopen("karaokeinfo.txt", "w");
system("cls");
printf("Please Enter customer's ID to be deleted : ");
fflush(stdin);
gets(del);
for (k = 0; k < 50; k++)
{
if (strcmp(details[k].id, del) == 0)
{
strcpy(details[k].id, "");
strcpy(details[k].name, "");
printf("Delete Successful!");
z = 1;
for (h = 0; h < i; h++)
{
fprintf(A, "%s\n", (details[h].id), h);
fprintf(A, "%s\n", (details[h].name), h);
}
fclose(A);
Cont();
}
}
if (z == 0)
{
printf("customer not found!\n");
Cont();
fclose(A);
}
}
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <dos.h>
#include <ctype.h>
void Cont();
int contt()
{
FILE *A;
char enter[100];
A = fopen("karaokeinfo.txt", "w"); // Open file in write mode
fclose(A); // Close File after writing
return(0);
}
void Cont() /*Function to ask whether the user want to continue using the program or not.*/
{
struct New
{
char id[10];
char name[30];
char roomsize[50];
char timetouse[50];
};
struct New details[50];
int h;
int i;
int j;
int k;
int l;
int m;
int n;
int o;
int p;
//char yes[5];
char kvar = 'y';
//while (true)
//{
printf("\n\tWould you like to continue ?(Y/N)\n");
gets(kvar);
if ((kvar == 'Y') || (kvar == 'y'))
{
printf("Yes chosen");
main();
}
else if ((kvar == 'N') || (kvar == 'n'))
{
//continue;
exit(0);
printf("thanx for using ... ");
}
else
{
printf("Invalid Selection! Please enter Y or N!( Y = Yes | N = No )\n");
}
//}
}
///each function was in header file except the main//
There is already another main function in the rest of your code. Decide which you need and remove the other.
Error C2084 function already has a body
To solve:
Make sure you didn't define a function that uses the same name twice.
Anyone know how to read a text file into a struct array? I've been trying to figure out how to do so to no avail.
Here's the function header
int getRawData(FILE* fp, struct nameRecord records[], int currSize)
where the first parameter is passed a file already open for reading, the second an array of nameRecord structs, and the third the number of records currently in that array. The function is supposed to read the data from the file into the array placing it at the end of the array. It then returns the total number of records in the array after reading the file.
I'm also at a loss at initializing the number of elements for the nameRecord struct array. We've never been taught memory allocation and the problem doesn't make any mention of how many records are within the files, making initialization an excercise in frustration. So far, I'm taking advice from someone at another forum and using malloc, but I don't even really know what it does.
Some info on the program itself to provide context:
program will ask the user to enter a name (you may assume that the
name will be no more than 30 characters long). It will then find the
popularity of the name between 1921 and 2010 and print out a chart and
graph. The program will then ask the user if they wish to do another
analysis and repeat the process.
The program will pull information from the following data sources in
determining the popularity of a name.
ontario female baby names ontario male baby names
Note that some names are considered both male and female so your
program will needs the data from both files regardless of the name
entered.
My attempt at the function:
//function that reads and places the read files into the struct arrays
int getRawData(FILE* fp, struct nameRecord records[], int currSize) {
int i;
for(i = 0; i < currSize; i++) {
fscanf(fp, "%[^,],%d,%d", records[i].name, &records[i].year, &records[i].frequency);
}
And here's the entire program:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
struct nameRecord {
char name[31];
int year;
int frequency;
};
void allCaps(char[]);
int getRawData(FILE*, struct nameRecord[], int);
void setYearTotals(struct nameRecord, int, int);
void setNameYearTotals(char, struct nameRecord, int, int);
void getPerHundredThousand(int, int, double);
void printData(double);
void graphPerHundredThousand(double);
int main(void)
{
int currSizem = 0;
int currSizef = 0;
struct nameRecord *records;
FILE* fp = NULL;
FILE* fp2 = NULL;
char name[31];
printf("Please enter your name: ");
scanf("%30[^\n]", name);
printf("your name is %s\n", name);
//opening both male and female name files and reading them in order to get the total number of records in the array
fp = fopen("malebabynames.csv", "r");
if (fp != NULL) {
printf("file opened\n");
while(3 == fscanf(fp, "%[^,],%d,%d", records[currSizem].name, &records[currSizem].year, &records[currSizem].frequency)) {
currSizem++;
}
} else {
printf("file failed to open\n");
}
if(currSizem > 0) {
records = malloc(currSizem * sizeof(struct nameRecord));
}
fp2 = fopen("femalebabynames.csv", "r");
if (fp != NULL) {
printf("file opened\n");
while(3 == fscanf(fp2, "%[^,],%d,%d", records[currSizef].name, &records[currSizef].year, &records[currSizef].frequency)) {
currSizef++;
}
} else {
printf("file failed to open\n");
}
if(currSizef > 0) {
records = malloc(currSizef * sizeof(struct nameRecord));
}
return 0;
}
//function that automatically capitalizes the users inputted name
void allCaps(char s[]) {
while(*s != '\0') {
*s = toupper((unsigned char) *s);
s++;
}
}
//function that reads and places the read files into the struct arrays
int getRawData(FILE* fp, struct nameRecord records[], int currSize) {
int i;
for(i = 0; i < currSize; i++) {
fscanf(fp, "%[^,],%d,%d", records[i].name, &records[i].year, &records[i].frequency);
}
return 0;
}
approximately as follows :
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
struct nameRecord {
char name[31];
int year;
int frequency;
};
int getRawData(FILE*, struct nameRecord[], int);
int main(void){
const char *MaleFilePath = "malebabynames.csv";
const char *FemaleFilePath = "femalebabynames.csv";
int currSizem = 0;
int currSizef = 0;
FILE* mfp = NULL;
FILE* ffp = NULL;
struct nameRecord *recordsOfMale, *recordsOfFemale;
//opening both male and female name files and reading them in order to get the total number of records in the array
mfp = fopen(MaleFilePath, "r");
if (mfp != NULL) {
int dummy;
printf("file opened\n");
//line count
while(1 == fscanf(mfp, " %*[^,],%*d,%d", &dummy)){
++currSizem;
}
} else {
printf("file(%s) failed to open\n", MaleFilePath);
exit(EXIT_FAILURE);
}
if(currSizem > 0) {
recordsOfMale = malloc(currSizem * sizeof(struct nameRecord));
if(recordsOfMale == NULL){
perror("malloc for Male records");
exit(EXIT_FAILURE);
}
}
rewind(mfp);
if(currSizem != getRawData(mfp, recordsOfMale, currSizem)){
fprintf(stderr, "I could not read a record for the specified number\n"
"at reading %s\n", MaleFilePath);
exit(EXIT_FAILURE);
}
fclose(mfp);
//Do something
free(recordsOfMale);
return 0;
}
//function that reads and places the read files into the struct arrays
int getRawData(FILE* fp, struct nameRecord records[], int currSize) {
int i;
for(i = 0; i < currSize; i++) {
if(3!=fscanf(fp, " %[^,],%d,%d", records[i].name, &records[i].year, &records[i].frequency))
break;
}
return i;
}
I'm trying to find if a record exists on a binary file by searching for a name.
Seems I'm not doing something right since the return of my "if" no matter the input it's always found when it doesn't exist.
The debugger states "if = A syntax error in expression", I'm not seeing it.
#ifndef DATA_PLAYER_H_INCLUDED
#define DATA_PLAYER_H_INCLUDED
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Player
{
char nome[50];
int pontos;
}Players;
void ViewPont();
void SearchPont();
#endif // DATA_PLAYER_H_INCLUDED
--
#include "DATA_PLAYER.h"
void ViewPont()
{
Players pl;
FILE *fp;
int i, pontos;
fp = fopen("Pontuacoes.dat", "rb+");
while((fread(&pl, sizeof(Players),1, fp)) != 0 )
{
printf("%s %d\n", pl.nome, pl.pontos);
}
fclose(fp);
}
void SearchPont()
{
char nam[50];
char ch;
Players pl;
FILE * fp;
fp = fopen("Pontuacoes.dat","rb+");
printf("\n nome das pont\n");
fflush(stdout);
scanf("%s", nam);
printf("%s", nam);
while((fread(&pl, sizeof(Players),1, fp)) != 0)
{
if((strcmp(pl.nome, nam))==0);
{
printf("\nregisto encontrado\n");
}
}
fclose(fp);
}
Silly me..........
if(strcmp(pl.nome, nam) ==0);
-> ; that little detail....
if(strcmp(pl.nome, nam) ==0)