I dont understand the appearent discrepency in the treatment of the variabe x, y, and z. Why y isn't treated as x and z? #include <stdio.h> #include <string.h> int main() { char result[100] = "Philippe Dupont 30"; char x[50]; char y[50]; int z; /*We use sscanf to give a value to the three variables x, y and z. the two first are strings and don't need &.*/ sscanf(result, "%s%s%d", x, y, &z); /*Printing the value of the variables works fine.*/ printf("%s\n", x); printf("%s\n", y); printf("%d\n", z); /*But when I want to print a string in which the variables are, the …

Member Avatar
Member Avatar
+0 forum 2

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

** # 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

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

Hi :). I don't found good examples for function sscanf(). Can you help me please with this situation? #include <cstdio> #include <iostream> using namepsace std; int main(int argc, char const *argv[]) { string way = "main/articles/animals/giraffe"; char arr[256]; char arr2[256]; sscanf(way.c_str(), "%[^'/']/", arr); cout << arr << endl; return 0; } I need in one string "**main**" and in the second "**articles/animals/giraffe**". How can I get the second part? And how can I use only "%" - without "%s" for string. Is it possible have string instead of **char arr[256]**? Thanks a lot :)!

Member Avatar
Member Avatar
+0 forum 2

How can i make sscanf() skip all whitespace characters?I read from a file and i dont know where are the characters. eg.->@Solomon Islands ,i need "Solomon Islands" in one string e.g->AGAF (AFT) – Afutara Airport – Afutara ,i need "Afutara Airport" in one string.

Member Avatar
Member Avatar
+0 forum 7

I am trying to read a csv file and store it into a 2D array, However it give me "segmentation fault" each time I run it. Here is my code [CODE] #include <stdlib.h> int main(void) { const char filename[] = "a.txt"; FILE *file = fopen(filename, "r"); if ( file != NULL ) { char *line; int i = 0, j=0, read=0; double array [2][10]; line= malloc (80 * sizeof (char)); while ( i < 2 ) { if ( fgets(line, sizeof line, file) == NULL ) { break; } for (j=0;j <20 ; j++){ sscanf(line, "%lf,",&array[i][j],&read ); //printf("%d ",read); line+=read; …

Member Avatar
Member Avatar
+0 forum 3

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.