pastebin - collaborative debugging tool
513.kpaste.net RSS


LINE 32-37: CHANGE DIRECTORY CODE
Posted by Anonymous on Sat 15th Oct 2011 01:20
raw | new post

  1. //-std=c99 to compile
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include <stdlib.h>
  6.  
  7. int main() {
  8.         while(1){
  9.                 printf("%s$ ", getcwd(NULL, 0) );
  10.  
  11.                 const int MAXWORDS = 100, MAXLEN = 1000;
  12.                 char * argv[MAXWORDS ];
  13.                 char line[ MAXLEN ];
  14.                 int n = 0;
  15.                 //printf( "enter some words: " );
  16.                 fgets( line, MAXLEN, stdin );
  17.                 char * p = strtok( line, " \n" );
  18.  
  19.                 while( n < MAXWORDS &&  p != NULL  ) {
  20.                         argv[n++] = p;
  21.                         p = strtok( NULL, "  \n" );
  22.                 }
  23.                 argv[n++]=(char*)0;
  24.  
  25.                 char * basepath[100];
  26.                 char * pathtoken;
  27.                 char * pPath;
  28.                 char * temppath;
  29.                 int basepathindex=0;
  30.                 int pathfound = 0;
  31.  
  32.                 int cdStatus;
  33.                 cdStatus = chdir( argv[1] );
  34.                 if (cdStatus == 0)
  35.                         printf( "Change directory successful" );
  36.                 else
  37.                         printf( "Change dir. failed" );
  38.         }
  39.         return 0;
  40. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at