Search Results

Search found 58 results on 3 pages for 'sscanf'.

Page 1/3 | 1 2 3  | Next Page >

  • sscanf + c99 not working on some platforms ?

    - by Jane
    When I compile a simple Hello World! program that uses the sscanf function on my local Debian lenny x64, it works. But when I upload the same program to the server running CentOS x86, it will not work. If I do not use sscanf, then the program works on both computers. gcc -std=c99 -O2 -pipe -m32 If I compile it with sscanf but without -std=c99, then it works on both computers. gcc -O2 -pipe -m32 What is the problem with sscanf and c99 on CentOS x86 ? I thought that compiling with the -m32 flag would work on all Linuxes ? (I have limited access to the CentOS server, so I do not have access to error messages.)

    Read the article

  • sscanf wrapping function to advance string pointer in C

    - by Dusty
    I have a function that makes a series of calls to sscanf() and then, after each, updates the string pointer to point to the first character not consumed by sscanf() like so: if(sscanf(str, "%d%n", &fooInt, &length) != 1) { // error handling } str+=length; In order to clean it up and avoid duplicating this several times over, i'd like to encapsulate this into a nice utility function that looks something like the following: int newSscanf ( char ** str, const char * format, ...) { int rv; int length; char buf[MAX_LENGTH]; va_list args; strcpy(buf, format); strcat(buf, "%n"); va_start(args, format); rv = vsscanf(*str, buf, args, &length); va_end(args); *str += length; return rv; } Then I could simply the calls as below to remove the additional parameter/bookkeeping: if(newSscanf(&str, "%d", &fooInt) != 1) { // error handling } Unfortunately, I can't find a way to append the &length parameter onto the end of the arg list directly or otherwise inside newSscanf(). Is there some way to work around this, or am I just as well off handling the bookkeeping by hand at each call?

    Read the article

  • Convert string to GUID with sscanf

    - by Andy Li
    I'm trying to convert a string to GUID with sscanf: GUID guid; sscanf( "11111111-2222-3333-4455-667788995511", "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", &guid.Data1, &guid.Data2, &guid.Data3, &guid.Data4[0], &guid.Data4[1], &guid.Data4[2], &guid.Data4[3], &guid.Data4[4], &guid.Data4[5], &guid.Data4[6], &guid.Data4[7]); However, in runtime, it fails and exits with "Error: Command failed". Why? How to fix it? I do not want to compile with /clr so cannot use System.

    Read the article

  • reading a string with spaces with sscanf

    - by SDLFunTimes
    For a project I'm trying to read an int and a string from a string. The only problem is sscanf appears to break reading an %s when it sees a space. Is there anyway to get around this limitation? Here's an example of what I'm trying to do: #include<stdio.h> #include<stdlib.h> int main(int argc, char** argv) { int age; char* buffer; buffer = malloc(200 * sizeof(char)); sscanf("19 cool kid", "%d %s", &age, buffer); printf("%s is %d years old\n", buffer, age); return 0; } What it prints is: "cool is 19 years old" where I need "cool kid is 19 years old". Does anyone know how to fix this?

    Read the article

  • sscanf for doubles

    - by bobobobo
    This is a simple problem, but I can't see it: char *s = "f 8.649292" ; double d ; sscanf( s, "f %f", &d ) ; printf( "d is %f\n", d ) ; Why is d not containing the double value 8.649292?

    Read the article

  • sscanf with multiple spaces?

    - by jamall55
    Hi. sscanf(text, "%s %s", name, company); parses 'ian mceknis' but it also parses 'ian mceknis' and so on. How can i make this to parse only the first one? It must contain only one space not more. Thank you.

    Read the article

  • Using sscanf to parse two strings out

    - by Jessica
    I have a semi xml formatted file that contains line with the following format: <param name="Distance" value="1000Km" /> The first char in the string is usually a TAB or spaces. I've been using the following to try to parse the two strings out (from name and value): if(sscanf(lineread, "\t<param name=\"%s\" value=\"%s\" />", name, value) == 1) { //do something } name and value are char* Now, the result is always the same: name gets parse (I need to remove the quotes) and name is always empty. What am I doing wrong? Thanks, code is appreciated. Jess.

    Read the article

  • Is there a way to use sscanf with stdin?

    - by j_eng
    I have a program that either takes data from a file or from the standard input. I wrote code for scanning the file using sscanf. I was wondering if I could reuse that code but with stdin instead of using scanf? Ex: How could I modify this so that it works with standard input? while(fgets(buffer, MAX_LEN, input) != NULL) { if (sscanf(buffer, "%s %s %s", one, two, three) == 3) { } }

    Read the article

  • Method sscanf() ambiguous behavior

    - by Carmen Cojocaru
    I am trying to understand how sscanf() works. I ran some examples from this page: http://docs.roxen.com/pike/7.0/tutorial/strings/sscanf.xml and they don't work on my platform. I can't understand why. For instance: "sscanf("4711bar", "%d%s", a, b);" makes the program exit with an error... Here is one of the examples that work: "sscanf("foo", "f%s", a);". Does anybody know why? Do they work on your platforms? Thank you. This is my code: int main(void){ char *b = (char*)malloc(sizeof(char)*100); int a = 0; sscanf("4711bar", "%d%s", a, b); printf("%d", a); printf("%s", b); }

    Read the article

  • ISO C90 forbids mixed declarations and code sscanf

    - by Need4Sleep
    I'm getting a strange error attempting to compile my unit test code,. For some reason the compiler treats my sscanf call as a mixed declaration? I don't quite understand, here is the entire error: cc1: warnings being treated as errors /home/brlcad/brlcad/src/libbn/tests/bn_complex.c: In function 'main': /home/brlcad/brlcad/src/libbn/tests/bn_complex.c:53: error: ISO C90 forbids mixed declarations and code make[2]: *** [src/libbn/tests/CMakeFiles/tester_bn_complex.dir/bn_complex.c.o] Error 1 make[1]: *** [src/libbn/tests/CMakeFiles/tester_bn_complex.dir/all] Error 2 make: *** [all] Error 2 int main(int argc, char *argv[]) { double expRe1, expIm2, expSqRe1, expSqIm2; double actRe1, actIm2, actSqRe1, actSqIm2; actRe1 = actIm2 = actSqRe1 = actSqIm2 = expRe1 = expIm2 = expSqRe1 = expSqIm2 = 0.0; bn_complex_t com1,com2; //a struct that holds two doubles if(argc < 5) bu_exit(1, "ERROR: Invalid parameters[%s]\n", argv[0]); sscanf(argv[1], "%lf,%lf", &com1.re, &com1.im); /* Error is HERE */ sscanf(argv[2], "%lf,%lf", &com2.re, &com2.im); sscanf(argv[3], "%lf,%lf", &expRe1, &expIm2); sscanf(argv[4], "%lf,%lf", &expSqRe1, &expSqIm2); test_div(com1, com2, &actRe1, &actIm2); test_sqrt(com1,com2, &actSqRe1, &actSqIm2); if((fabs(actRe1 - expRe1) < 0.00001) || (fabs(actIm2 - expIm2) < 0.00001)){ printf("Division failed...\n"); return 1; } if((fabs(actSqRe1 - expSqRe1) < 0.00001) || (fabs(actSqIm2 - expSqIm2) < 0.00001)){ printf("Square roots failed...\n"); return 1; } return 0; }

    Read the article

  • C++: parsing with simple regular expression or shoud I use sscanf?

    - by Helltone
    I need to parse a string like func1(arg1, arg2); func2(arg3, arg4);. It's not a very complex parsing problem, so I would prefer to avoid resorting to flex/bison or similar utilities. My first approch was to try to use POSIX C regcomp/regexec or Boost implementation of C++ std::regex. I wrote the following regular expression, which does not work (I'll explain why further on). "^" "[ ;\t\n]*" "(" // (1) identifier "[a-zA-Z_][a-zA-Z0-9_]*" ")" "[ \t\n]*" "(" // (2) non-marking "\[" "(" // (3) non-marking "[ \t]*" "(" // (4..n-1) argument "[a-zA-Z0-9_]+" ")" "[ \t\n]*" "," ")*" "[ \t\n]*" "(" // (n) last argument "[a-zA-Z0-9_]+" ")" "]" ")?" "[ \t\n]*" ";" Note that the group 1 captures the identifier and groups 4..n-1 are intended to capture arguments except the last, which is captured by group n. When I apply this regex to, say func(arg1, arg2, arg3) the result I get is an array {func, arg2, arg3}. This is wrong because arg1 is not in it! The problem is that in the standard regex libraries, submarkings only capture the last match. In other words, if you have for instance the regex "((a*|b*))*" applied on "babb", the results of the inner match will be bb and all previous captures will have been forgotten. Another thing that annoys me here is that in case of error there is no way to know which character was not recognized as these functions provide very little information about the state of the parser when the input is rejected. So I don't know if I'm missing something here... In this case should I use sscanf or similar instead? Note that I prefer to use C/C++ standard libraries (and maybe boost).

    Read the article

  • Using sscanf for the dynamic delimiters (inputted by users) in parsing an input string in C? [migrated]

    - by Zuhakasa
    I'm encountering a problem in parsing a string using sscanf() function. My function gets 2 string parameters. One for input string and another one for a dynamic list of delimiters. How can I use sscanf to parse the input string with the defined delimiters inputted by users. For example: Myfunction(char * input_string, char * delimiter_list){ scanf("%s", input_string); scanf("%s", delimiter_list); sscanf(input_string, ???...); ................ }

    Read the article

  • fgets, sscanf, and writing to arrays

    - by alldavidsluck
    beginner question here, I haven't been able to find examples that relate. I'm working on a C program that will take integer input from stdin using fgets and sscanf, and then write it to an array. However, I'm not sure how to make fgets write to the array. #define MAXINT 512 char input[MAXINT] int main(void) { int i; int j; int count=0; int retval; while (1==1) { fgets(input, MAXINT[count], stdin); retval = sscanf(input, "%d", &i); if (retval == 1) { count = count++; } else if (retval != 1) { break; } } Would I simply put fgets in a for loop? or is it more complicated than that?

    Read the article

  • seg fault caused by malloc and sscanf in a function

    - by Framester
    Hi, I want to open a text file (see below), read the first int in every line and store it in an array, but I get an segmentation fault. I got rid of all gcc warnings, I read through several tutorials I found on the net and searched stackoverflow for solutions, but I could't make out, what I am doing wrong. It works when I have everything in the main function (see example 1), but not when I transfer it to second function (see example 2 further down). In example 2 I get, when I interpret gdb correctly a seg fault at sscanf (line,"%i",classes[i]);. I'm afraid, it could be something trivial, but I already wasted one day on it. Thanks in advance. [Example 1] Even though that works with everything in main: #include<stdio.h> #include<stdlib.h> #include<string.h> const int LENGTH = 1024; int main() { char *filename="somedatafile.txt"; int *classes; int lines; FILE *pfile = NULL; char line[LENGTH]; pfile=fopen(filename,"r"); int numlines=0; char *p; while(fgets(line,LENGTH,pfile)){ numlines++; } rewind(pfile); classes=(int *)malloc(numlines*sizeof(int)); if(classes == NULL){ printf("\nMemory error."); exit(1); } int i=0; while(fgets(line,LENGTH,pfile)){ printf("\n"); p = strtok (line," "); p = strtok (NULL, ", "); sscanf (line,"%i",&classes[i]); i++; } fclose(pfile); return 1; } [Example 2] This does not with the functionality transfered to a function: #include<stdio.h> #include<stdlib.h> #include<string.h> const int LENGTH = 1024; void read_data(int **classes,int *lines, char *filename){ FILE *pfile = NULL; char line[LENGTH]; pfile=fopen(filename,"r"); int numlines=0; char *p; while(fgets(line,LENGTH,pfile)){ numlines++; } rewind(pfile); * classes=(int *)malloc(numlines*sizeof(int)); if(*classes == NULL){ printf("\nMemory error."); exit(1); } int i=0; while(fgets(line,LENGTH,pfile)){ printf("\n"); p = strtok (line," "); p = strtok (NULL, ", "); sscanf (line,"%i",classes[i]); i++; } fclose(pfile); *lines=numlines; } int main() { char *filename="somedatafile.txt"; int *classes; int lines; read_data(&classes, &lines,filename) ; for(int i=0;i<lines;i++){ printf("\nclasses[i]=%i",classes[i]); } return 1; } [Content of somedatafile.txt] 50 21 77 0 28 0 27 48 22 2 55 0 92 0 0 26 36 92 56 4 53 0 82 0 52 -5 29 30 2 1 37 0 76 0 28 18 40 48 8 1 37 0 79 0 34 -26 43 46 2 1 85 0 88 -4 6 1 3 83 80 5 56 0 81 0 -4 11 25 86 62 4 55 -1 95 -3 54 -4 40 41 2 1 53 8 77 0 28 0 23 48 24 4 37 0 101 -7 28 0 64 73 8 1 ...

    Read the article

  • Objective C LValue required as unary '&' operand

    - by Bob
    Hello! In my code, I get this error when I try to get a pointer to my class property. (I wrote a small *.OBJ file translator in Python, discarding the normals) CODE: //line: line of text const char *str = [line UTF8String]; Point3D *p1, *p2, *p3; p1 = [Point3D makeX:0 Y:0 Z:0]; p2 = [Point3D makeX:0 Y:0 Z:0]; p3 = [Point3D makeX:0 Y:0 Z:0]; sscanf(str, "t %f,%f,%f %f,%f,%f %f,%f,%f",(&[p1 x]),&([p1 y]),&([p1 z]),&([p2 x]),&([p2 y]),&([p2 z]),&([p3 x]),&([p3 y]),&([p3 z])); Triangle3D *tri = [Triangle3D make:p1 p2:p2 p3:p3];

    Read the article

  • Convert function to read from string instead of file in C

    - by Dusty
    I've been tasked with updating a function which currently reads in a configuration file from disk and populates a structure: static int LoadFromFile(FILE *Stream, ConfigStructure *cs) { int tempInt; ... if ( fscanf( Stream, "Version: %d\n",&tempInt) != 1 ) { printf("Unable to read version number\n"); return 0; } cs->Version = tempInt; ... } to one which allows us to bypass writing the configuration to disk and instead pass it directly in memory, roughly equivalent to this: static int LoadFromString(char *Stream, ConfigStructure *cs) A few things to note: The current LoadFromFile function is incredibly dense and complex, reading dozens of versions of the config file in a backward compatible manner, which makes duplication of the overall logic quite a pain. The functions that generate the config file and those that read it originate in totally different parts of the old system and therefore don't share any data structures so I can't pass those directly. I could potentially write a wrapper, but again, it would need to handle any structure passed in in a backwards compatible manner. I'm tempted to just pass the file as is in as a string (as in the prototype above) and convert all the fscanf's to sscanf's but then I have to handle incrementing the pointer along (and potentially dealing with buffer overrun errors) manually. This has to remain in C, so no C++ functionality like streams can help here Am I missing a better option? Is there some way to create a FILE * that actually just points to a location in memory instead of on disk? Any pointers, suggestions or other help is greatly appreciated.

    Read the article

  • Quick question regarding this issue, Why doesnt it print out the second value(converted second value

    - by sil3nt
    Quick question, What have I done wrong here. The purpose of this code is to get the input into a string, the input being "12 34", with a space in between the "12" and "32" and to convert and print the two separate numbers from an integer variable known as number. Why doesn't the second call to the function copyTemp, not produce the value 34?. I have an index_counter variable which keeps track of the string index and its meant to skip the 'space' character?? what have i done wrong? thanks. #include <stdio.h> #include <string.h> int index_counter = 0; int number; void copyTemp(char *expr,char *temp); int main(){ char exprstn[80]; //as global? char tempstr[80]; gets(exprstn); copyTemp(exprstn,tempstr); printf("Expression: %s\n",exprstn); printf("Temporary: %s\n",tempstr); printf("number is: %d\n",number); copyTemp(exprstn,tempstr); //second call produces same output shouldnt it now produce 34 in the variable number? printf("Expression: %s\n",exprstn); printf("Temporary: %s\n",tempstr); printf("number is: %d\n",number); return 0; } void copyTemp(char *expr,char *temp){ int i; for(i = index_counter; expr[i] != '\0'; i++){ if (expr[i] == '0'){ temp[i] = expr[i]; } if (expr[i] == '1'){ temp[i] = expr[i]; } if (expr[i] == '2'){ temp[i] = expr[i]; } if (expr[i] == '3'){ temp[i] = expr[i]; } if (expr[i] == '4'){ temp[i] = expr[i]; } if (expr[i] == '5'){ temp[i] = expr[i]; } if (expr[i] == '6'){ temp[i] = expr[i]; } if (expr[i] == '7'){ temp[i] = expr[i]; } if (expr[i] == '8'){ temp[i] = expr[i]; } if (expr[i] == '9'){ temp[i] = expr[i]; } if (expr[i] == ' '){ temp[i] = '\0'; sscanf(temp,"%d",&number); index_counter = i+1; //skips? } } // is this included here? temp[i] = '\0'; }

    Read the article

  • Scanning string in perl

    - by Alphaneo
    What is the best way to achieve sscanf like functionality in perl? I am looking now looking at the sscanf module, Which is better, Option-1: Going sscanf way? Option-2: Regex way? [I am a beginner when it comes to Regex]

    Read the article

  • scanf("%d", char*) - char-as-int format string?

    - by SF.
    What is the format string modifier for char-as-number? I want to read in a number never exceeding 255 (actually much less) into an unsigned char type variable using sscanf. Using the typical char source[] = "x32"; char separator; unsigned char dest; int len; len = sscanf(source,"%c%d",&separator,&dest); // validate and proceed... I'm getting the expected warning: argument 4 of sscanf is type char*, int* expected. As I understand the specs, there is no modifier for char (like %sd for short, or %lld for 64-bit long) is it dangerous? (will overflow just overflow (roll-over) the variable or will it write outside the allocated space?) is there a prettier way to achieve that than allocating a temporary int variable? ...or would you suggest an entirely different approach altogether?

    Read the article

  • Using C preprocessor to construct a string literal for scanf?

    - by Brett
    I'm attempting to create an sscanf string literal to aid in buffer overrun prevention in C99. The goal is something like: #define MAX_ARG_LEN 16 char arg[MAX_ARG_LEN] = ""; if (sscanf(arg, "%"(MAX_ARG_LEN-1)"X", &input) > 0) The obvious "manual" solution is something like: #define MAX_ARG_LEN 16 #define MAX_ARG_CHARS "15" char arg[MAX_ARG_LEN] = ""; if (sscanf(arg, "%"MAX_ARG_CHARS"X", &input) > 0) However, I would prefer something to automatically generate "%15X" given a buffer size of 16. This link is almost works for my application: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string but it does not handle the -1. Suggestions?

    Read the article

  • Issues glVertexAttribPointer last 2 parameters?

    - by NoobScratcher
    Introduction Hello I will start out by explaining my setup, showing samples as I go along explaining the situation. I'm using these tools: OpenGL 3.3 GLSL 330 C++ Problem The problem is when I render the wavefront obj 3d model it gives a very weird visual glitch the model was supposed to be a square but instead its a triangluated mess with parts of the vertexes pointing in a stretched direction in massive amounts towards the bottom left side of the frustum.... Explanation: I'm using std::vectors to store my wavefront .obj model data using sscanf to get the floating point values into the structure members x,y,z and store them into the Points structure variable p; int index = IndexAssigner(1, 1); ifstream file (list[index].c_str() ); points.push_back(Point()); Point p; int face[4]; while (!file.eof() ) { char modelbuffer[10000]; file.getline(modelbuffer, 10000); switch(modelbuffer[0]) { case 'v' : sscanf(modelbuffer, "v %f %f %f", &p.x, &p.y, &p.z); points.push_back(p); break; case 'f': sscanf(modelbuffer, "f %d %d %d %d", face, face+1, face+2, face+3 ); faces.push_back(face[0]); faces.push_back(face[1]); faces.push_back(face[2]); faces.push_back(face[3]); } //Turn on FileReader aka "RENDER CODE" FileReader = true; } then I render the Points vector using the .data() member of std::vectors to the frustum. Other declarations: int numfloats = 4; float* point=reinterpret_cast<float*>(&points[0]); int num_bytes=numfloats*sizeof(float); Vector declarations: struct Point {float x, y , z; }; std::vector<int>faces; std::vector<Point>points; Render code: glGenBuffers(1, &vertexbuffer); glGenTextures(1, &ModelTexture); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glBindTexture(GL_TEXTURE_3D, ModelTexture); glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, ModelSurface->w, ModelSurface->h, 0, GL_BGR, GL_UNSIGNED_BYTE, ModelSurface->pixels); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glBufferData(GL_ARRAY_BUFFER, sizeof(points), points.data(), GL_STATIC_DRAW); glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE,num_bytes ,points.data()); glEnableVertexAttribArray(3); //Translation Process GLfloat TranslationMatrix[] = { 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0 }; //Send Translation Matrix up to the vertex shader glUniformMatrix4fv(translation, 1, TRUE, TranslationMatrix); glDrawElements( GL_QUADS, faces.size(), GL_UNSIGNED_INT, faces.data()); I tried looking at what was causing this and went through every function every parameter ,etc looked at the man pages. Then found out that it could be my glVertexAttribPointer. Here are the man pages for glVertexAttribPointer http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml The last 2 parameters is my problem How do I write those 2 last parameters do I try putting the data from Points into it?. glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE,num_bytes ,points.data()); How does it work with vectors? Is it fast?* if you can not be bothered too look at the man pages here is the scripts coming from the man pages directly. Stride Specifies the byte offset between consecutive generic vertex attributes. If stride is 0, the generic vertex attributes are understood to be tightly packed in the array. The initial value is 0. Pointer Specifies a pointer to the first component of the first generic vertex attribute in the array. The initial value is 0. If you want my full source - http://ideone.com/fPfkg Thanks Again if you do read this.

    Read the article

  • c++ File input/output

    - by Myx
    Hi: I am trying to read from a file using fgets and sscanf. In my file, I have characters on each line of the while which I wish to put into a vector. So far, I have the following: FILE *fp; fp = fopen(filename, "r"); if(!fp) { fprintf(stderr, "Unable to open file %s\n", filename); return 0; } // Read file int line_count = 0; char buffer[1024]; while(fgets(buffer, 1023, fp)) { // Increment line counter line_count++; char *bufferp = buffer; ... while(*bufferp != '\n') { char *tmp; if(sscanf(bufferp, "%c", tmp) != 1) { fprintf(stderr, "Syntax error reading axiom on " "line %d in file %s\n", line_count, filename); return 0; } axiom.push_back(tmp); printf("put %s in axiom vector\n", axiom[axiom.size()-1]); // increment buffer pointer bufferp++; } } my axiom vector is defined as vector<char *> axiom;. When I run my program, I get a seg fault. It happens when I do the sscanf. Any suggestions on what I'm doing wrong?

    Read the article

  • Parsing mathematical experssions with two values that have parenthesis and minus signs

    - by user45921
    I'm trying to parse equations like these which only has two values or the square root of a certain value from a text file: 100+100 -100-100 -(100)+(-100) sqrt(100) by the minues signs, parenthesis and the operator symbol in the middle and the square root, and I have no idea how to start off... I've got the file part done and the simple calculation parts except that I couldnt get my program to solve the equations in the above. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> main(){ FILE *fp; char buff[255], sym,sym2,del1,del2,del3,del4; double num1, num2; int ret; fp = fopen("input.txt","r"); while(fgets(buff,sizeof(buff),fp)!=NULL){ char *tok = buff; sscanf(tok,"%lf%c%lf",&num1,&sym,&num2); switch(sym){ case '+': printf("%lf\n", num1+num2); break; case '-': printf("%lf\n", num1-num2); break; case '*': printf("%lf\n", num1*num2); break; case '/': printf("%lf\n", num1/num2); break; default: printf("The input value is not correct\n"); break; } } fclose(fp); } that is what have I written for the other basic operations without parenthesis and the minus sign for the second value and it works great for the simple ones. I'm using a switch method to calculate the add, sub, mul and divide but I'm not sure how to properly use the sscanf function (if I am not using it properly) or if there is another way using a function like strtok to properly parse the parenthesis and the minus signs. Any kind help?

    Read the article

  • Simple string parsing with C++

    - by Andreas Brinck
    I've been using C++ for quite a long time now but nevertheless I tend to fall back on scanf when I have to parse simple text files. For example given a config like this (also assuming that the order of the fields could vary): foo: [3 4 5] baz: 3.0 I would write something like: char line[SOME_SIZE]; while (fgets(line, SOME_SIZE, file)) { int x, y, z; if (3 == sscanf(line, "foo: [%d %d %d]", &x, &y, &z)) { continue; } float w; if (1 == sscanf(line, "baz: %f", &w)) { continue; } } What's the most concise way to achieve this in C++? Whenever I try I end up with a lot of scaffolding code.

    Read the article

1 2 3  | Next Page >