Hello, am working on a program for the U.S. Department of Labor. I am working on two programs for the state of Oregon, and the program that reads data and displays on a screen is working correctly. The code reads tax rates for a specific tax schedule and puts htam in a one-dimensional array. The code in the screen program follows: `for (iLine = 0, j = 1; iLine <= 9; ++iLine, j++) { if ((iLine * 9) < knri) { strcpy(tempString, ""); for (mm = 0; mm < 5; mm++) { strncat(tempString, &range[k][mm], 1); } mvwaddstr(win,3,xx,tempString); k = k …

Member Avatar
Member Avatar
+0 forum 2

Hello, I am having a problem with the fgets statement not reading data correctly. It reads most of the data I need without a problem, but three lines of data are not read correctly. The code in question follows: 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 *****/ fgets(str, 82, fip); fprintf(ff16, "\nLIST OF SOLVENCY SURCHARGE RATES\n"); fgets(str, 82, fip); if (sscanf(&str[1], "%d", &baseYearSurcharge) < 1) { fprintf(ff16, …

Member Avatar
Member Avatar
+0 forum 10

I don't know what's wrong but the succeeding strings are not properly read by fgets. else { initArray(word1); //first string fgets(word1, 29, fileIn); printf("word1: %s\n", word1); len = strlen(word1); if(word1[len-1] == '\n') word1[len-1] = '\0'; while(!feof(fileIn)) { //succeeding strings in next line initArray(word1); fgets(word1, 30, fileIn); printf("word1: %s\n", word1); len = strlen(word1); if(word1[len-1] == '\n') word1[strlen(word1)-1] = '\0'; fgetc(fileIn); } fclose(fileIn); } } texts: ABCD asnjf fkj read: ABCD snjf kj Can you give me an idea what's wrong?

Member Avatar
Member Avatar
+0 forum 4

This is an example of a singly linked list allowing you to enter a number of names and associated ages. The twist is that the names are inserted into the list in ascending order. When the list is displayed, it is already sorted by name. Note: This is not an exercise in safe data input. While precautions have been taken, any fool can stress the language easily.

Member Avatar
Member Avatar
+1 forum 7

I have two different text files, one of them contains a text, the other one works as a dictionary. The dictionary has some words line by line with their description beside them separated by a comma. I'm supposed to search for all these words in the text and then replace them with their description. I thought after opening both for reading, I should load their contents into two arrays, I'm just a bit confused about the dictionary part since it should be read line by line and then each line should be broken into two parts. **I just really need …

Member Avatar
Member Avatar
+0 forum 1

Hi all, I have to find out to write a function that can serve PDF documents (invoices) in the browser window. My challenge is that the PDF fiels is on another server, which I do have access to. Can I somehow just create a link on the site, and then get the pdf from the different server to appear, by using fgets? I know fgets can be used for cvs data - but I need to show the entire document/transfer it from one server to another. Any ideas is appreciated, as I need to create this function asap :-) Best …

Member Avatar
Member Avatar
+0 forum 20

[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

I've read many threads on how to remove a new line character '\n' using fgets()-- however, how would one go about removing a new line character simply by using getchar() ?

Member Avatar
Member Avatar
+0 forum 11

////////////////////////////////////////////////////////////////////////////////// // Now I have an idea how to get my strings from the file so that I can properly // play with them (with fstream I did not have the string "in my clutches" quite // the way I wanted it). However, now I have a problem with my looping because // this way, I am seeing the last line *TWICE* in my output, so feof must trigger // from the error caused by reading past the end of the file or what just is the // reason? // // Is there an elegant way to exit from this? …

Member Avatar
Member Avatar
+0 forum 5

This is what the question is stating: Write a program that inputs a line of text using function fgets() into a char array s[90], then it outputs the line converted to uppercase. For function [ICODE]fgets[/ICODE] to be used, am i correct if I understand that the user doesn't have to input anything but the text should be get from the file only? Keeping with the same function, I found that this is how the function is used. [ICODE]fgets ( char * str, int num, FILE * stream );[/ICODE] Am I correct if I understand that: [ICODE]char *str[/ICODE] => the array …

Member Avatar
Member Avatar
+0 forum 11

I've been stuck on this for hours because I really don't understand file descriptors and how successfully print a file to one. Basically, I want to be able to open a file and then echo its contents a character at a time to a socket file descriptor. The code below will hopefully help you to understand, and I've made a start on what I think is correct. I just can't figure out what to include in the while loop, although I think it is through use of [B]char *fgets[/B] and [B]int fputs[/B]. Any help whatsoever will be greatly appreciated. [CODE] …

Member Avatar
Member Avatar
+0 forum 1

This program should extract the first line. Somehow I'm getting the last line instead of the first... This is the textfile: [ICODE]N100 G96 S200 N115 G0 X600 Z-1004.95 T11 D2 M3 M7 H10 N125 G0 X500 N130 G1 X419 F0.5 N135 G1 Z-1004 N140 G0 X500 N145 G0 Z-419.7 N150 G0 X405[/ICODE] Trying to get the first line and place it in a character array with this .c program : [CODE]#include <stdio.h> #include <stdlib.h> int main (int argc, char *argv[]) { FILE *filePtr; int i = 0; char line[255]; if ((filePtr=fopen(argv[1], "r")) == NULL) { printf("Cannot open file.\n"); return -1; …

Member Avatar
Member Avatar
+0 forum 1

I'm trying to read user input and store it as a string including the whitespace. I did a search for a solution and was pointed to fgets() or scanf(%[^\n], str). But both these solutions give me an error. This is what I have: [CODE] scanf("%d", &input); if (input == 1){ int pr; char na[MAX_CHARACTERS+1]; printf("\nEnter the name: "); scanf("%[^\t\n]", &na); while (strlen(na)>MAX_CHARACTERS){ printf("\nName is too long, enter new name: "); scanf("%[^\t\n]", &na); }// end na check printf("\nEnter priority: "); scanf("%d", &pr); while (pr>MAX_PRIORITY || pr <MIN_PRIORITY){ printf("\nBad priority, enter new priority (0-100): "); scanf("%d", &pr); }//end pr check[/CODE] It works …

Member Avatar
Member Avatar
+0 forum 6

Hello, I have two very simple questions. 1. I want to use fgets(text, MAX_WORDS, stdin) to read in a string file, where my array is text[MAX_WORDS]. But is there a way to make stdin a pointer instead to a 2nd array which can be a buffer? 2.Whats the difference between fgets(text, MAX_WORDS, stdin) and fgets(text, sizeof(MAX_WORDS), stdin)? Thanks

Member Avatar
Member Avatar
+0 forum 8

Hello, I have this assignment in C. The problem is that the functions have to be placed in separate files instead of just one. I haven't done that before. It seems code that would have run if the program was written in one file doesn't work when the functions are separated. Why? I've tried this on both Visual Studio 2005 and 2010 on Windows XP with the same result. Here's a small bit of code: main.c [CODE]#include <stdio.h> #include <stdlib.h> #include "my_func.h" int main() { FILE *fp; char s[30]; fp=fn_fop(); fn_out(&fp); fclose(fp); printf("\nsuccess\n"); return 0; }[/CODE] my_func.c [CODE]#include <stdio.h> #include …

Member Avatar
Member Avatar
+0 forum 2

Could someone please explain the following code to me? It's not for class, more personal curiosity. Thanks in advance [code=cpp] while(!feof(infp)) { fgets(buf, MAXLINE, infp); fputs(buf, outfp); } [/code] what I'm mainly curious about is the argument o feof "infp."

Member Avatar
Member Avatar
+0 forum 1

Hi Everybody, FYI (In order to get a feeling with the time it takes to send command strings to signal generators via a GPIB bus, I want to send a voltage level high pulse to an oscilloscope. Ones the RF signal arrives via a detector diode, The pulse and the video signal are triggered and I can compare the timing.) I've got a twofold problem with the code I've been trying to write: 1. I want the pulse (On the serial Com1 port) coming on just before I send the command string to the signal generator (HPIB). The error I …

Member Avatar
Member Avatar
+0 forum 1

Ok, so I'm trying to write an emulator for a simple processor architecture and I've ran into a strange problem. I decided to read the input code once through to see how many lines there were, then set up an array of that length, and then go through the file a second time to read the code into the array. Each line is 8 hex characters long. The first time through, everything goes as normal, but the second time through, fgets reads the entire file, which is wierd. It's been a while since I've programmed in C and even then …

Member Avatar
Member Avatar
+0 forum 14

Hi! I need help to my Turbo C program.. I need to create a program that will ask the "Starting X:", "Starting Y:", Ending X:", and Ending Y:" on different shapes.. this is how the program should be: [CODE]SQUARE: starting X: starting Y: ending X: ending Y: CIRCLE: Starting X: Ending Y: Radius: LINE: Starting X: Ending Y:[/CODE] and also [CODE]POLYGON:[/CODE] ...the user will write numbers in starting X, starting Y, ending X, ending Y, and radius, after encoding the numbers, the result will create the shape that the user chose and according to their X and Y and radius …

Member Avatar
Member Avatar
+0 forum 39

Hi again. I have a file that have about 1000 lines, and then, time by time I need to read some of this lines, for example: 13:00:00 read lines 01 to 100; 13:30 read lines 101 to 400; .... 15:00:00 read lines 900 to 1000. There is a way to start the pointer of fgets or fscanf starts at the specific line? Or i realy need to scan all file until the start line?

Member Avatar
Member Avatar
+0 forum 2

[CODE] #include<stdio.h> int main() { FILE *reading; FILE *writing; int condition,condition2; char input[100]; char save[100]; printf("Type a name to open for reading : "); scanf("%s",input); reading = fopen(input,"r"); /* OPENS the file name we typed above for reading */ if(reading != NULL) { do { condition = fgets(save,30,reading); printf("\n%s",save); }while(condition != NULL); } else { printf("\nFile not found!!!!!\n"); } getchar(); getchar(); fclose(reading); return(0); } [/CODE] in the do while loop the programme picks up 100 characters from the file... but what if a file is not hundred characters... then the programme is showing lines 2-3 times for completion of hundred …

Member Avatar
Member Avatar
+0 forum 2

Some issues, such as leading whitespace and trailing characters that cannot be part of a number, were not handled in [url=http://www.daniweb.com/code/showsnippet.php?codeid=266]Read an Integer from the User, Part 1[/url]. Here such issues receive lip service.

Member Avatar
Member Avatar
+1 forum 1

The End.