Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Raul.Leemet
/
IAG0582
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4afa4bca
authored
Apr 19, 2017
by
Raul.Leemet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file
parent
11cc75a4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
0 deletions
Praktikum12/dynaamilineLug.txt
Praktikum12/dynaamilineLug.txt
0 → 100644
View file @
4afa4bca
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN 255
typedef struct
{
int GameID;
char PlayerName[LEN];
char KilledName[LEN];
}action;
action *ReadFromFile(int *Total, char *FileName);
void PrintStruct(int total,action *kill);
int main(void)
{
int PlayersTotal;
char FileName[]={"frags.txt"};
action *kill=ReadFromFile(&PlayersTotal,FileName);
PrintStruct(PlayersTotal,kill);
free(kill);
return 0;
}
action *ReadFromFile(int *Total, char *FileName)
{
int i=0;
action buf;
action *pTemp=NULL;
action *pArr=NULL;
FILE *fi=fopen(FileName,"r");
if(fi==NULL)
{
exit(1);
}
while(fscanf(fi,"%d%s%s",&buf.GameID,buf.PlayerName,buf.KilledName)!=EOF)
{
pTemp=(action*)realloc(pArr,sizeof(action)*(i+1));
if( pTemp == NULL)
{
printf("Memory Allocation Failed");
fclose(fi);
free(pArr);
exit(1);
}
else
{
pArr=pTemp;
(pArr+i)->GameID=buf.GameID;
strcpy((pArr + i)-> PlayerName,buf.PlayerName);
strcpy((pArr + i)-> KilledName,buf.KilledName);
i++;
}
}
printf("%d\n",i);
fclose(fi);
*Total=i;
return pArr;
}
void PrintStruct(int total,action *kill)
{
int i;
puts("Data:");
for(i = 0; i < total; i++)
{
printf("%d %s %s\n", (kill + i)->GameID,(kill+ i)->PlayerName, (kill + i)->KilledName);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment