Sponsored Content
Full Discussion: help with sscanf()!
Top Forums Programming help with sscanf()! Post 302308257 by Zykl0n-B on Friday 17th of April 2009 01:28:28 PM
Old 04-17-2009
help with sscanf()!

Hi everybody,

i need help with this function, i'm programming in CGI with C and i can't make this work.

QUERY_STRING is something like: user=MYUSER&pass=MYPASS

So, what i want is to store the strings containing the username and the password into str1 and str2 respetively, here's the code:

Code:
#include <stdio.h>
#include <stdlib.h>
 
int main(void){
char *data, *str1, *str2;
 
/*... HTML stuff ...*/
 
data = getenv("QUERY_STRING");
 
if(data==NULL){
printf("<H1>Error passing data to CGI Script</H1>");
exit(1);
}
 
else
sscanf(data, "user=%s&pass=%s", &str1, &str2);
 
printf("Username: %s\n", str1);
printf("Password: %s\n", str2);
return(0);
}

But i'm getting an error... it works perfectly with numbers, but i need it to work like this, with strings.
Am i missing something? Please, help me!!!

Last edited by Zykl0n-B; 04-17-2009 at 02:33 PM..
Zykl0n-B
 

7 More Discussions You Might Find Interesting

1. Programming

sscanf function is failing

Please delete this thread. (0 Replies)
Discussion started by: jxh461
0 Replies

2. Programming

sscanf !!

I have a string Form this string, I want to extract I am unable to do that with sscanf because of the space between the words. What else can I use? #include <stdio.h> char buf_2; int main() { char *buf_1 = "\\\\?\\whats going on"; sscanf(buf_1,... (4 Replies)
Discussion started by: the_learner
4 Replies

3. Programming

help with sscanf

I need to match a float inside a very long string (about 5000 chars) with sscanf. (I trimmed the string in this example.) I can't seem to match all the chars that come before and after the float. int main(void) { char A = ""; strcat(A, " hello world! WORD' name='5.3498' hello world! ... (1 Reply)
Discussion started by: limmer
1 Replies

4. Programming

Help with sscanf

sscanf does not stop at the first "&". How can I extract "doe" ? char A = "name=john&last=doe&job=vacant&"; char B = "last"; char C = ""; char *POINTER = strstr(A, B); sscanf(POINTER + strlen(B), "=%s%*", C); printf("%s\n", C); // doe&job=vacant& (2 Replies)
Discussion started by: limmer
2 Replies

5. Programming

using sscanf

How can I separetely extract the string and int after "dribble" ? (sscanf must limit TEXT to 9 chars to avoid buffer overflows.) How come this code does not work with "dribbletext08" but does with "dribbletext05" ? int main(void) { char TEXT = ""; int NUMBER = 0; ... (2 Replies)
Discussion started by: cyler
2 Replies

6. Programming

sscanf() weired behaviour

Hi with the following code int a, b; while ((n = readline (connfd, buf, sizeof(buf)-1)) > 0) { buf = '\0'; if (sscanf(buf,"%d %d",&a,&b) != 2) snprintf (buf, sizeof(buf), "data error\r\n"); else { printf("\nRecvd %d and %d",a,b); ... (1 Reply)
Discussion started by: princebadshah
1 Replies

7. Programming

Format specifier for sscanf() in C

Hello, I have formatted lines delimited by colon ":", and I need to parse the line into two parts with sscanf() with format specifiers. infile.txt: Sample Name: sample1 SNPs : 91 MNPs : 1 Insertions : 5 Deletions ... (13 Replies)
Discussion started by: yifangt
13 Replies
HOBBITGRAPH.CGI(1)					      General Commands Manual						HOBBITGRAPH.CGI(1)

NAME
hobbitgraph.cgi - CGI to generate Xymon trend graphs SYNOPSIS
hobbitgraph [options] DESCRIPTION
hobbitgraph.cgi is invoked as a CGI script via the hobbitgraph.sh CGI wrapper. hobbitgraph.cgi is passed a QUERY_STRING environment variable with the following parameters: host Name of the host to generate a graph for service Name of the service to generate a graph for disp Display-name of the host, used on the generated graphs instead of hostname. graph Can be "hourly", "daily", "weekly" or "monthly" to select the time period that the graph covers. first Used to split multi-graphs into multiple graphs. This causes hobbitgraph.cgi to generate only the graphs starting with the "first'th" graph and continuing for "count". count Number of graphs in a multi-graph. upper Set the upper limit of the graph. See rrdgraph(1) for a description of the "-u" option. lower Set the lower limit of the graph. See rrdgraph(1) for a description of the "-l" option. graph_start Set the starttime of the graph. This is used in zoom-mode. graph_end Set the end-time of the graph. This is used in zoom-mode. action=menu Generate an HTML page with links to 4 graphs, representing the hourly, weekly, monthly and yearly graphs. Doesn't actually gen- erate any graphs, only the HTML that links to the graphs. action=selzoom Generate an HTML page with link to single graph, and with JavaScript code that lets the user select part of the graph for a zoom-operation. The JavaScript invokes hobbitgraph.cgi with "action=showzoom" to generate the zoomed graph webpage. action=showzoom Generate HTML with a link to the zoomed graph image. This link goes to an "action=view" invocation of hobbitgraph.cgi. action=view Generate a single graph image. OPTIONS
--config=FILENAME Loads the graph configuration file from FILENAME. If not specified, the file $BBHOME/etc/hobbitgraph.cfg is used. See the hobbit- graph.cfg(5) for details about this file. --env=FILENAME Loads the environment settings defined in FILENAME before executing the CGI. --rrddir=DIRECTORY The top-level directory for the RRD files. If not specified, the directory given by the BBRRDS environment is used. --save=FILENAME Instead of returning the image via the CGI interface (i.e. on stdout), save the generated image to FILENAME. --debug Enable debugging output. ENVIRONMENT
QUERY_STRING Provided by the webserver CGI interface, this decides what graph to generate. FILES
hobbitgraph.cfg: The configuration file determining how graphs are generated from RRD files. SEE ALSO
hobbitgraph.cfg(5), xymon(7), rrdtool(1) Xymon Version 4.2.3: 4 Feb 2009 HOBBITGRAPH.CGI(1)
All times are GMT -4. The time now is 12:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy