Thread: weird errors

  1. #1
    Registered User
    Join Date
    Jul 2007
    Location
    Texas
    Posts
    103

    weird errors

    ok so I am just writing to play around with my new mac and I got a lot of errors compiling it. I figured all of them out but two. Heres the code:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    
    main()
    {
    	
    	char choice[8];
    	
    	
    	printf("	This program can open applications or delete files\n");
    	printf("	Please select what you like to do\n");
    	printf("	enter 'Delete' to delete files, or 'open' to open\n");
    	scanf(" %s", choice);
    	
    	if((toupper(choice[1]) == 'O')||(toupper(choice[1]) == 'D'))
    	{
    	
    		if(toupper(choice) == 'Open')
    		{
    	
    	
    			char empty1[25];
    			char empty2[55];
    			char applic[15];
    	
    			printf("Type in the name of the app\n");
    			scanf(" %s", applic);
    	
    			sprintf(empty1, "open -a %s", applic);
    	
    			sprintf(empty2, "%s.app", empty1);
    	
    			system(empty2);
    		}
    		if(toupper(choice) == 'Delete')
    		{
    			
    			char location[35], cdcomm[39], name[23], systemname[28];
    			
    			printf("Type the location of the file\n");
    			printf("Ex: Macintosh HD is in the folder 'Desktop'\n");
    			printf("Keep in mind capitalization DOES COUNT\n");
    			printf("so now tell me the address of the file\n");
    			scanf(" %s", location);
    			
    			sprintf(cdcomm, "cd %s", location);
    			system(cdcomm);
    			
    			printf("Now tell me the name and type of file it is\n");
    			printf("Ex: examplefile.txt\n");
    			scanf(" %s", name);
    			
    			sprintf(systemname, "rm %s", name);
    		}
    		
    	}
    	else
    	{
    		Printf("An error occured please restart\n");
    	}
    	
    	return 0;
    }
    and heres the errors I got compiling with gcc:

    new-hostesktop Alex$ gcc final.c
    final.c:36:25: warning: character constant too long for its type
    Undefined symbols:
    "_Printf", referenced from:
    _main in ccjQRlV5.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    new-hostesktop Alex$

    with the "36" and the "25" being the lines that the errors are on

    if you know why or what the deal is please tell me. Oh and btw the part where it opens an app worked exactly as it was when I had a program that just opened an app.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >toupper(choice)
    toupper takes a char for its argument, not a char array. choice is a char array.

    > Printf("An error occured please restart\n");
    Should be:
    Code:
    		printf("An error occured please restart\n");

  3. #3
    Registered User
    Join Date
    Jul 2007
    Location
    Texas
    Posts
    103
    Hey, ok that worked, but I found a few more errors. Here is the revised code:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    
    main()
    {
    	
    	char choice[8];
    	
    	
    	printf("	This program can open applications or delete files\n");
    	printf("	Please select what you like to do\n");
    	printf("	enter 'Delete' to delete files, or 'open' to open\n");
    	scanf(" &#37;s", choice);
    	
    	if((toupper(choice[0]) == 'O')||(toupper(choice[0]) == 'D'))
    	{
    	
    		if(toupper(choice[0]) == 'O')
    		{
    	
    	
    			char empty1[25];
    			char empty2[55];
    			char applic[15];
    	
    			printf("Type in the name of the app\n");
    			scanf(" %s", applic);
    	
    			sprintf(empty1, "open -a %s", applic);
    	
    			sprintf(empty2, "%s.app", empty1);
    	
    			system(empty2);
    		}
    		if(toupper(choice[0]) == 'D')
    		{
    			
    			char location[35], cdcomm[39], name[23], systemname[28];
    			
    			printf("Type the location of the file\n");
    			printf("Ex: Macintosh HD is in the folder 'Desktop'\n");
    			printf("Keep in mind capitalization DOES COUNT\n");
    			printf("so now tell me the address of the file\n");
    			
    			scanf(" %s", location);
    			
    			sprintf(cdcomm, "cd %s", location);
    			system("cd ~/");
    			
    			system(cdcomm);
    			
    			
    			printf("Now tell me the name and type of file it is\n");
    			printf("Ex: examplefile.txt\n");
    			scanf(" %s", name);
    			printf(" %s", name);
    			
    			sprintf(systemname, "rm %s", name);
    			system(systemname);
    		}
    		
    	}
    	else
    	{
    		printf("An error occured please restart\n");
    	}
    	
    	return 0;
    }
    The problem is now the cd %s part doesn't work, it won't go to the right directory... do I have to make it all in one system() function command?

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >do I have to make it all in one system() function command?
    I would guess yes. I'm pretty sure that when you change the directory using system(), it only changes the directory during the execution of that one call. Once control returns to the program, the current directory is restored to what it was originally.

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by swoopy View Post
    >do I have to make it all in one system() function command?
    I would guess yes. I'm pretty sure that when you change the directory using system(), it only changes the directory during the execution of that one call. Once control returns to the program, the current directory is restored to what it was originally.
    The cwd only changes in the instance of the shell that system() launches and has execute the given parameter. The cwd in the program that calls system() never actually changes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HELP with DX9 Errors!!!
    By Tommaso in forum Game Programming
    Replies: 7
    Last Post: 06-28-2006, 02:51 PM
  2. Errors with header files in OpenGL using VisualC++
    By wile_spice in forum Game Programming
    Replies: 3
    Last Post: 06-22-2006, 08:56 AM
  3. Weird Errors in VS 2003
    By Devil Panther in forum Windows Programming
    Replies: 1
    Last Post: 10-01-2005, 06:16 AM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM