Thread: 0 compile error but 2 build error. need help please!

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    28

    0 compile error but 2 build error. need help please!

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #define howto "Enter a number 1-8 to select from the menu\n\n\n"
    #define menu "*********************\n    1. Preorder\n    2. Inorder\n    3. Postorder\n    4. Update\n    5. Load\n    6. Save\n    7. Help\n    8. Quit\n*********************"
    
    int list();
    void load(int, char);
    
    
    FILE * input;
    
    int main(int argc, char* argv[])
    {
    	int option;
    	
    	printf(howto);
    	option = list();
    	
    	while (option != 8)
    	{
    		system("cls");
    		option = list();
    	
    		switch(option)
    		{
    		case 5:
    			load(argc, *argv[1]);
    			break;
    		}
    
    	
    	}
    
    	
    	
    
    	return 0;
    }
    
    int list()
    {
    	int option;
    	
    
    	printf(menu);
    	scanf("%d", &option);
    
    	while (option < 1 || option > 8)
    	{
    		system("cls");
    		printf(menu);
    		scanf("%d", &option);
    	}
    
    	return option;
    }
    
    void load(int argc, char* argv[1])
    {
    
    	
    	int c;
    	int num;
    	int count = 0;
    	
    
    	input = fopen(argv[1],"r");
    	num = atoi(argv[1]);
    
    	while((c = fgetc(input)) != EOF) 
    	{
    
    		if(count < num) 
    		}
    			fputc(c, stdout);
    			count++;
    		}
    		else 
    		}
    			fprintf(stdout,"\n");
    			count = 0;
    
    		}
    
    	}
    
    }
    is what i have so far. the menu stuff all works fine, i've been testing as i've been going. i assume that these errors have something to do with the passing of argv and argc. i'm pretty confused.

  2. #2
    Registered User lobo's Avatar
    Join Date
    Oct 2001
    Posts
    71
    If you want to pass filename to load() function, you need to pass char *, not just char. So far, you are only passing first char of argv[1]. Use

    void load(int argc, char *filename)

    In your main, pass just argv[1], not *argv[1]

    Finally, in your load function, use name this way:

    void load(int argc, char* filename)
    {
    input = fopen(filename, "r");
    ...

    You should check if argv[1] is valid at all...

    If you still get the error msgs, post them...

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    28
    i half understand..
    but i thought argv[1] refers to the 2nd thing written on the command line..

    eg.


    c:/fts text.txt

    would run the file fts and then argv[1] would be test.txt

    would you be able to explain that? as i've obviously misunderstood. thanks

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Quote Originally Posted by jibbles
    i half understand..
    but i thought argv[1] refers to the 2nd thing written on the command line..

    eg.


    c:/fts text.txt

    would run the file fts and then argv[1] would be test.txt

    would you be able to explain that? as i've obviously misunderstood. thanks
    Since you have read things that you don't understand, maybe you can enlighten yourself by writing a program that shows what argv[] is.

    On the other hand, I'll write it.

    Wait a minute.

    (Sound of clock ticking for 123 seconds.)

    OK, here it is:

    Try it yourself; maybe this can lead to understanding:

    Code:
    #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;
    }
    Regards,

    Dave
    Last edited by Dave Evans; 08-30-2004 at 07:58 AM.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Dave Evans
    Since you have read things that you don't understand, maybe you can enlighten yourself by writing a program that shows what argv[] is.

    On the other hand, I'll write it.

    Wait a minute.

    ...
    You could have always just pointed them at the FAQ entry on the topic.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Quote Originally Posted by quzah
    You could have always just pointed them at the FAQ entry on the topic.

    Quzah.
    The point that I was trying to make was that it takes next to no time to write a simple program to find out answers to questions like that. It literally took me less time to write and execute the program than to click on the link and look through the examples and cut-and-paste one into my text editor and then to compile and execute it.

    I don't mind giving the personal touch, like supplying ten lines of code to help someone. I hope that once they see how easy it is, that next time they will try something like that on their own. Not because I don't like to answer questions, but because I think that it helps people more if they see that they can help themselves.

    Regards,

    Dave

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PlaySound
    By cangel in forum C++ Programming
    Replies: 16
    Last Post: 10-08-2009, 05:29 PM
  2. How to build, run Boland C++ 6 source file via VS2005?
    By userpingz in forum C++ Programming
    Replies: 2
    Last Post: 05-21-2009, 03:25 AM
  3. Replies: 0
    Last Post: 10-07-2008, 12:09 PM
  4. build tree of directories sub-directories using linked-lists
    By geekoftheweek in forum C Programming
    Replies: 3
    Last Post: 10-02-2008, 11:13 PM
  5. how do i compile a program that deals w/classes?
    By Shy_girl_311 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2001, 02:32 AM