-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdynamically_change_data.c
81 lines (54 loc) · 1.25 KB
/
dynamically_change_data.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//Header Files
#include<stdio.h>
#include<stdlib.h>
//Main Function
//agrc - stores Counts No. of Arguments
//argv - stores actual Arguments
int main(int argc,char *argv[]){
//Check No. of Arguments
if(argc==4){
//File Pointer
FILE *fp;
//Opening File
fp=fopen(argv[1],"r+");
//Check File For Content
if(fp!=NULL){
printf("\nReading .... \n");
//Variables
int roll_no,marks, return_value,found=0;
char name[20];
fpos_t pos; //Position Of The File Pointer
//Core Logic
//Get the file pointers Position in the Beginning
fgetpos(fp,&pos);
while(1){
//Scanning the File
return_value=fscanf(fp,"%d\t%s\t%d\n",&roll_no,name,&marks);
//If End Of File then BREAK
if(return_value==-1){
break;
}
//Check for Roll No
if(roll_no == atoi(argv[2])){
printf("Found\n");
fsetpos(fp,&pos);
fprintf(fp,"%d\t%s\t%d\n",roll_no,name,(marks+atoi(argv[3])));
found++;
}
}
//If Roll No not Found
if(found<0){
printf("\n Not Found !!!\n");
}
//Close File
fclose(fp);
}else{
//File Not Found
printf("\nFile Doesn't Exist \n");
}
}else{
//Invalid No. of Arguments
printf("\nInvalid No. Of Arguments \n");
}
return 0 ;
}