User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 428,197 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,193 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 1340 | Replies: 1
Reply
Join Date: Oct 2004
Posts: 1
Reputation: Fleetfoot18 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Fleetfoot18 Fleetfoot18 is offline Offline
Newbie Poster

How come my argc keeps giving me -1???

  #1  
Oct 13th, 2004
I'm suppose to execute the program in cmd prompt like this:

fifo.exe data.txt

However, I cannpt even get the program name which is fifo.exe.
I found out that argc (parameter of main) does not even go to 1.
It shows -1 instead.
Why is this so?
Anyone can help me?!?!

I actually created a class right above the main program.
Below is how i type the main:
int main (int argc, char *argv[])
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Posts: 3,655
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 145
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: How come my argc keeps giving me -1???

  #2  
Oct 13th, 2004
#include <stdio.h>

int main(int argc, char *argv[])
{
   int i;
   printf("argc = %d\n", argc);
   for (i = 0; i < argc; ++i)
   {
	  printf("argv[%d] = \"%s\"\n", i, argv[i]);
   }
   return 0;
}

/* my output
C:\Test>testpp.exe data.txt
argc = 2
argv[0] = "C:\Test\testpp.exe"
argv[1] = "data.txt"
*/
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 3:06 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC