- //-std=c99 to compile
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #include <stdlib.h>
- int main() {
- while(1){
- printf("%s$ ", getcwd(NULL, 0) );
- const int MAXWORDS = 100, MAXLEN = 1000;
- char * argv[MAXWORDS ];
- char line[ MAXLEN ];
- int n = 0;
- //printf( "enter some words: " );
- fgets( line, MAXLEN, stdin );
- char * p = strtok( line, " \n" );
- while( n < MAXWORDS && p != NULL ) {
- argv[n++] = p;
- p = strtok( NULL, " \n" );
- }
- argv[n++]=(char*)0;
- char * basepath[100];
- char * pathtoken;
- char * pPath;
- char * temppath;
- int basepathindex=0;
- int pathfound = 0;
- int cdStatus;
- cdStatus = chdir( argv[1] );
- if (cdStatus == 0)
- printf( "Change directory successful" );
- else
- printf( "Change dir. failed" );
- }
- return 0;
- }
LINE 32-37: CHANGE DIRECTORY CODE
Posted by Anonymous on Sat 15th Oct 2011 01:20
raw | new post
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.