Solved

perl in c

Posted on 1998-12-24
2
136 Views
Last Modified: 2010-04-15
Could anyone help me to solve this problem ?

I would like to use pure C to write a very simple cgi script.

OK. This script will get an input( integer ) from the user
on the net, after user entered an integer and pressed the submit button. That number will store in a text file called num.txt. So, the text file should not be overwrote, it should be able to store as many as it can.

Please tell me how to call that script from the html and do I have to change any thing in server conf file ?
0
Comment
Question by:tanc02
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
jhurst earned 100 total points
ID: 1255413
#include <stdio.h>
#include <stdlib.h>
#include <stdring.h>


int main(void)
  {
  FILE *numTxt=fopen("nu.m.txt","at"); /* the file will be appended to */
  char str[80];                                      /* just some work space */
  char *ptr;                                          /* will search soon */

  fgets(str,70.stdin);                            /* get the post parameters */

  ptr=strchr(str,'=');                              /* so we can get the first value */

  fprintf(numTxt,"%d\n",atoi(ptr+1));    /* the value is right after the =-sign */
 
  fclose(numTxt);                                /* we are done with it */
 
  printf("Content-Type: text/html\n\n"); /* send a reply */
 
  printf("<html><body>We Received the Number: %d<p>\n",atoi(ptr+1));
                                                          /* let him see what we did */
  printf("</body></html>\n");              /* finish the generated page *
  return(0);                                        /* we are done */
  }



The html:
<html>
<body>
<form action=your-cgi-name-path method=post>
Ypur Number: <input type=text name=theNumber>
<input type=submit>
</form>
</body>
</html>

0
 

Expert Comment

by:sobhan102398
ID: 1255416
atoi converts string to integer
i=atoi("1001")
gives i as 1001
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
why debugging a macro i s difficult 10 43
negation in C function 14 171
Line meaning 9 91
Micosft Excel/VBA - Clear content of cell when adjoining cells have content 6 36
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question