Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
sakomm
/
jgfjfg
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
b1f764df
authored
2 months ago
by
sakomm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file
parents
master
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
0 deletions
fafasd
fafasd
0 → 100644
View file @
b1f764df
#include <stdio.h>
/*
struct PR2_data {
char names[10];
int value;
char hexnum[10];
};
* */
typedef struct PR2_data {
char names[10];
int value;
char hexnum[10];
} PR2_data;
void func(int);
int main(void){
FILE *task_file;
int i;
PR2_data data[10];
char buf[256];
char buf2[3][256];
int counter = 0;
char file_name[] = "PR2_data.txt";
task_file = fopen(file_name,"r");
if(task_file == NULL){
printf("File not found.");
return -1;
}
//This counts the num of elements in file (30)
while(fscanf(task_file, "%s", buf) != EOF){//reads single element into char
//array buffer
counter++;//increment counter for each element read
}
printf("%d\n", counter);
rewind(task_file);//Reset file pointer to start, to read file again
counter = 0;
//This counts the num of lines in file (10)
while(fscanf(task_file, "%s %s %s", buf2[0], buf2[1], buf2[2]) != EOF){
//reads entire line(need to know line elements)
counter++;//
}
printf("%d\n", counter);
rewind(task_file);//Reset file pointer to start, to read file again
i = 0;
while(fscanf(task_file, "%s %d %s",
data[i].names, &data[i].value, data[i].hexnum) != EOF){
printf("%s %d %s\n", data[i].names, data[i].value, data[i].hexnum);
i++;
}
return 0;
}
This diff is collapsed.
Click to expand it.
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