Pelles C > General discussions

int main(int argc, char *argv[], char *env[]) Related Problem

(1/1)

royski:
Hi

Attempting to port a Linux program from book titled "C Programming in Linux) (circa 2008) to my Windows 8.1 running Pelles C latest version.  Here following is the code running in console mode.

#include <stdio.h>
#include <string.h>

                      /*  MAIN PROGRAM BODY  */

int main(int argc, char *argv[], char *env[])


   _clrscr();    // Erase the user's output screen

   printf("\n\n");

   printf("Content-type:text/html\n\n");
   printf("<html>\n");
   printf("<body bgcolor=\"%s\">\n", argv[1]);
   printf("<body>\n");
   printf("<html>\n");

   printf("\n\n");
   return 0;        // another way of ending program
   
}                      /*  END OF MAIN PROGRAM  */

Does not work in Pelles C, running on Windows 8.1.  Might be because program was written to run in Linux.  Appears to be related to the statement "int main(int argc, char *argv[], char *env[])".  The last argument does not appear to work.  I don't get the webpage to open at all.  As though the printf statements for the generation of the webpages are not working.

What am I NOT doing or doing WRONG??

Thanks in advance!!

royski
Email:  Removed. (It's not a good idea to show personal Email on a public forum, unless you like spam...)

TimoVJL:
 ;)

--- Code: ---#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
                      /*  MAIN PROGRAM BODY  */
int main(int argc, char *argv[]/*, char *env[]*/)
{
   _clrscr();    // Erase the user's output screen
   char *env = getenv("QUERY_STRING");
   printf("\n\n");

   printf("Content-type:text/html\n\n");
   printf("<html>\n");
   printf("<body bgcolor=\"%s\">\n", argv[1]);
   printf("<body>\n");
   printf("<html>\n");

   printf("\n\n");
   return 0;        // another way of ending program
}                      /*  END OF MAIN PROGRAM  */
--- End code ---

Scripter:

--- Quote from: royski on June 12, 2016, 08:33:59 PM ---Hi

Attempting to port a Linux program from book titled "C Programming in Linux) (circa 2008) to my Windows 8.1 running Pelles C latest version.  Here following is the code running in console mode.

--- Code: ---#include <stdio.h>
#include <string.h>

                      /*  MAIN PROGRAM BODY  */

int main(int argc, char *argv[], char *env[])
--- End code ---
           
Does not work in Pelles C, running on Windows 8.1.  Might be because program was written to run in Linux.  Appears to be related to the statement "int main(int argc, char *argv[], char *env[])".  The last argument does not appear to work.  I don't get the webpage to open at all.  As though the printf statements for the generation of the webpages are not working.

What am I NOT doing or doing WRONG??

Thanks in advance!!

--- End quote ---

The correct main function for console programs in Windows is...

--- Code: ---int _cdecl main(int argc, char **argv)
  {
     // lots of fun stuff

    return 0;
  }

--- End code ---

You will also find that Linux console code is significantly different than Windows console code... so much so that porting from one to another almost always either fails or takes a ton of work.

If you are looking for a good tutorial on C programming in Windows, try this...

https://kldp.org/files/c+in+21+days.pdf

.. just save the PDF to disk for future reference.



royski:
Thanks to the respondes, greatly appreciated and easily understood.   I correctly my program and it ran OK.

Adios Amigos.

TheRaven:
_clrscr() from as Linux console command/function translates into a string "cls" passed into the Windows console as argument.

This confused the h3ll out of me some time ago as I cut my teeth in the black box while using Linux and FreeBSD due to the fact that I was always GUI centralized using Windows. Very easy to translate after the initial learning curve, but as stated above can/will be very time consuming especially if the original source is somewhat sloppy. Translate > optimize > enjoy.

Navigation

[0] Message Index

Go to full version