• Lucid Dreaming - Dream Views




    Results 1 to 8 of 8

    Thread: C Help

    Hybrid View

    1. #1
      What's up <span class='glow_006400'>[SomeGuy]</span>'s Avatar
      Join Date
      Nov 2007
      LD Count
      About 1
      Gender
      Location
      Tmux on Debian
      Posts
      2,862
      Likes
      130
      DJ Entries
      4

      C Help

      Code:
      #include <stdio.h>   
      #include <string.h>   
      
      
      void strip_newline( char *str, int size )
      {
          int i;
      
          for (  i = 0; i < size; ++i )
          {
              if ( str[i] == '\n' )
              {
                  str[i] = '\0';
                  return;   
              }
          }
      }
      
      int main()
      {
          char command[100];
          FILE *fp;
      
          printf( "Select Program\n" );
          fgets( command, 100, stdin );
      
          strip_newline( command, 100 );
          
          if ( strcmp ( command, "Programmer's Notepad" ) == 0)                               
          {
              fp=fopen("Apps/PN/pn.exe", "r");
          }
          fgets( command, 100, stdin );
          strip_newline( command, 100 );
          getchar();
          return 0;
      }
      Can somebody help me wit this? I want it so when you type "Programmer's Notepad", it opens Programmer's Notepad from a folder called apps.

      [Project Folder]
      Project.exe
      [Apps]
      [PN]
      pn.exe

      That's My file setup.

      Hey guys, I'm back. Feels good man
      ---------------------------------------------------
      WTF|Jesus lul
      spam removed

    2. #2
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      currently, you are just opening the external binary file for reading
      what you need is for the operating system to execute the program

      one way is the system() function

      If you use system() to execute an external program,
      you will lose all control over your program until the external program finishes
      (your program will just sit there, waiting)
      there are more elegant ways to execute external programs, and keep control
      but because you're dealing with OS specific things, it gets complicated, fast

      examples
      http://www.cprogramming.com/tips/sho...ount=30&page=1

      http://www.gidforums.com/t-3369.html

      just be careful with system()
      search and read up on it
      understand the problems, and why people advise against it's use
      Last edited by Ynot; 08-03-2008 at 10:04 AM.

    3. #3
      Member Achievements:
      1 year registered Veteran First Class 5000 Hall Points

      Join Date
      Sep 2004
      Gender
      Location
      Seattle, WA
      Posts
      2,503
      Likes
      217
      *wonders why anyone would want to type "Programmer's Notepad" instead of just "pn"*

    4. #4
      What's up <span class='glow_006400'>[SomeGuy]</span>'s Avatar
      Join Date
      Nov 2007
      LD Count
      About 1
      Gender
      Location
      Tmux on Debian
      Posts
      2,862
      Likes
      130
      DJ Entries
      4
      Okay, I will look into that. Also, how do I make it so it never really ends? Most programms I van write go along a timeline, and it ends. I know how to make it stop with getchar(),but that doesn;t really help. How would I make this more like a terminal? So where it stays open and allows peope tocontinuously write commands?

      Also, I don't really want to get into C right now,I just need to make a terminal like app in this as a quick project for some stuff.

      Hey guys, I'm back. Feels good man
      ---------------------------------------------------
      WTF|Jesus lul
      spam removed

    5. #5
      Member Achievements:
      1 year registered Veteran First Class 5000 Hall Points

      Join Date
      Sep 2004
      Gender
      Location
      Seattle, WA
      Posts
      2,503
      Likes
      217
      Quote Originally Posted by xXSomeGuyXx View Post
      Okay, I will look into that. Also, how do I make it so it never really ends? Most programms I van write go along a timeline, and it ends. I know how to make it stop with getchar(),but that doesn;t really help. How would I make this more like a terminal? So where it stays open and allows peope tocontinuously write commands?

      Also, I don't really want to get into C right now,I just need to make a terminal like app in this as a quick project for some stuff.
      If you want it to be like a terminal, you can always put the getchar inside a loop... something like

      Code:
          bool done = false;
          while( !done ) {
              fgets( command, 100, stdin );
              done = processCommand( command );
          }
      Of course, you don't have 'bool' if you're using a C compiler...

    6. #6
      What's up <span class='glow_006400'>[SomeGuy]</span>'s Avatar
      Join Date
      Nov 2007
      LD Count
      About 1
      Gender
      Location
      Tmux on Debian
      Posts
      2,862
      Likes
      130
      DJ Entries
      4
      Yeah, but then it doesn't read the if statements everytime.

      Hey guys, I'm back. Feels good man
      ---------------------------------------------------
      WTF|Jesus lul
      spam removed

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •