I am having a problem with reading input data after checking a position marker in the data file. The code that does the reading follows: fip = fopen("fprmf.txt","r"); . . . strcpy(passw,"P7"); fscanf(fip, "%3s", ckod); /* card # 164 */ fprintf(ff16,"\n\n%12s%12s\n", "card# 164 :", "Password "); printf("passwd is %s\n", ckod); if(strcmp(passw,ckod)!=0) { printf("\n%64s\n%80s\n", "E R R O R !", "Password is incorrect. Please resubmit."); exit(164); } /***** Cards 165 - 174 *****/ fprintf(ff16, "\nLIST OF SOLVENCY SURCHARGE RATES\n"); fscanf(fip, "%5.3f", &solvpctchkinitial); fscanf(fip, "%5.3f", &solvpctchkmaximum); fprintf(ff16, "INITIAL PERCENTAGE = %5.3f, MAXIMUM PERCENTAGE = %5.3f\n", solvpctchkinitial, solvpctchkmaximum); surchargeCheckPercent = solvpctchkinitial; for(i=1;i<=18; i++) …

Member Avatar
Member Avatar
+0 forum 1

** # import a data table with space? # ** Good day! I need to read in all the data in a file within column two and export it in a file. The issue is the data is not standard and has blank fields from time to time. It also has issues like "N/A" that i would want to delete. So i just need some direction. C... is a fickle beast ya know. The reason being i need to inport a printer file and process the information to export only the document numbers. for example... 10 HIHM07A1 10 Hj NDt …

Member Avatar
Member Avatar
+0 forum 13

I am trying read CSV files in a C program on an AIX system. I am having problems getting fscanf to recognize the comma delimeter. I have read previous posts on this issue, and used the techniques dicussed in those threads, but I am still having the issue. Specifically, this problem was in a thread from a year ago, and the solution was to remove the comma using %*c on integer/decimal fields, and adding a mask for string fields, i.e., %[^ \t\n\r\v\f,]%*c. I have tried that, but I still am not getting the fscanf to work. It reads all of …

Member Avatar
Member Avatar
+0 forum 5

i am writing this code for a school poject it gives mee segmentation fault .please help it scans iput of the form #include<stdio.h> #include<stdlib.h> struct time{ int hh,mm; }; struct date{ int day,month,year; }; struct student{ char firstname[20]; char lastname[20]; struct time entry; struct time leavetime; struct date dt; int bno; int rno; }; int main(void) { struct student stu1; FILE *file; file = fopen("inpt.txt", "r"); fscanf(" %s %s %2d:%2d %2d:%2d %2d/%2d/%4d %3d %3d", stu1.firstname,stu1.lastname,&stu1.entry.hh,&stu1.entry.mm,&stu1.leavetime.hh,&stu1.leavetime.mm, &stu1.dt.day,&stu1.dt.month,&stu1.dt.year,&stu1.bno,&stu1.rno); fclose(file); printf("%s %s %d:%d %d:%d %d/%d/%d %d %d", stu1.firstnamename,stu1.lastname,stu1.entry.hh,stu1.entry.mm,stu1.leavetime.hh,stu1.leavetime.mm ,stu1.dt.day,stu1.dt.month,stu1.dt.year,stu1.bno,stu1.rno); return(0); } Alex Smith 10:00 12:00 24/08/2012 342 618

Member Avatar
Member Avatar
+0 forum 1

Hello everyone I'm having a bit of trouble with C. Its been awhile and I was wondering if I'm on the right track I'm trying to read from a file and manipulate the data with a structure I created. The problem is the first two values in the text document will be used for the loop count and the next will be used to subtract from other values in the document. For instance the first value is 10 so go through 10 lines of the document and the next line is the date 20120803. I want to read these two …

Member Avatar
Member Avatar
+0 forum 7

Hello all! I have used this forum many times in the past to solve a variety of programming related problems, but am truly stumped on a segfault within a binary search tree. I have isolated the segfault to a fscanf statement that look legitamate to me. The following code blocks are the function that contains the fscanf statement: int fscan_unit(FILE *filep, object_t *object){ int status; /************************** SEGFAULT **************************/ status = fscanf(filep, "%d%d%d%s", &object->id, &object->section, &object->credits, object->course ); /************************** SEGFAULT **************************/ if(status == 4){ status = 1; } else if(status != EOF){ status = 0; } return status; } and the …

Member Avatar
Member Avatar
+0 forum 2

main.c #include <stdio.h> #include <stdlib.h> #define MAX_USERS 100 typedef struct Utilizadores{ char *login; char *pwd; } USERS; void ReadUsers(USERS user[]); int u = 0; int main(){ USERS user[MAX_USERS]; ReadUsers(user); return 0; } void ReadUsers(USERS user[]){ FILE *fp; fp = fopen("/home/Jiwe/Desktop/users.txt", "r"); while(fscanf(fp, "%s[^=]=%s\n", user[u].login, user[u].pwd) != EOF){ u++; } fclose(fp); } Hey guys, I get a segmentation fault error using the code above. For now I just want to read the login name and password of a user from a text file, so later I can show it. The text file is filled like this: LOGIN=PASS LOGIN2=PASS2 ... etc I …

Member Avatar
Member Avatar
+0 forum 5

it gets compiled but it crushes: "programm has stopped working" Please help me!!! this is the programm: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { FILE *fp; int i=0, n; char allwords[100][40]; fp=fopen("fraoules.txt","r"); if ( (fp=fopen("fraoules.txt","r") )==NULL ){ printf("To arxeio den mporese na anoixtei\n"); } while(strcmp( allwords[i],"telos")!=0){ fscanf(fp, "%s", allwords[i+1]); i++;} fclose(fp); for(n=0; n<i; n++) printf("%s", allwords[n]); system("PAUSE"); return 0; }

Member Avatar
Member Avatar
+0 forum 3

[CODE] FILE *ranch; FILE *myfile; char line[500]; case 1: ranch=fopen("garrudaRanch.txt ","w+"); if(ranch != NULL) { printf("Enter amount of Corral: \n"); scanf("%d",&corral); fprintf(ranch,"%d\n",corral); printf("Enter size of Corral: \n"); scanf("%d",&corrals); fprintf(ranch,"%d\n",corrals); } fclose(ranch); break; case 2: myfile=fopen("garrudaRanch.txt ","r+"); if(myfile != NULL) { //fscanf(myfile,"%s",line[1]); printf("Number of Corral: %s",line[1]); printf("Size of Corral: %s",line[2]); } else printf("File didnt open"); fclose(myfile); break; [/CODE] Can someone show me how to read from the file line by line please. It write the information to the file but i did some research but i keep failing. I try the fscanf and the gets but to no success.

Member Avatar
Member Avatar
+0 forum 1

Im still learning C and I have a few questions about making a array of strings. Im doing an assignment for school, and I'm a little stuck with my program. Here is my code so far: [CODE] #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]){ FILE* fin; int a; char myString[3];; fin=fopen(argv[1],"r"); fscanf((fin,"%s", &myString)!=EOF); putchar('\n'); printf("%s\n", myString); return 0; } [/CODE] What I am trying to accomplish is to create a program that will take individual characters from a file, each on a separate line, and compose them into a single string in memory while keeping the first character …

Member Avatar
Member Avatar
+0 forum 7

I am not getting all numbers but only last number while readind data from file. And it has to be done with fscanf function.[code]/* input n nunbers fom user and write it in the file.find it's sum and write the ans. in another file */ #include <stdio.h> #include <conio.h> void main() { int i,n,no,sum=0; FILE *fp,*fs; fp=fopen("d:\\tc\\bin\\strtNo.txt","w"); printf("%s","Enter value for n : "); scanf("%d",&n); for(i=0;i<n;i++) { printf("\n Enter the no : "); scanf("%d",&no); fprintf(fp,"%d\n",no); sum+=no; } fprintf(fp,"%d\n",99); fclose(fp); fs=fopen("d:\\tc\\bin\\strtSum.txt","w"); fprintf(fs,"%d",sum); fclose(fs); fp=fopen("d:\\tc\\bin\\strtNo.txt","r"); if(fp==NULL) { printf("ERROR"); } while((fscanf(fp,"%d\n",no))!=99) { printf("%d\n",no); } fclose(fp); getch(); }[/code]

Member Avatar
Member Avatar
+0 forum 9

The End.