Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while ((de = readdir(dr)) != NULL)
- printf("%s\n", de->d_name);
- ........................................................
- char *buf;
- buf=(char *)malloc(100*sizeof(char));
- getcwd(buf,100);
- printf("\n %s \n",buf);
- .....................
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- pid_t childPID = fork();
- if(childPID >0){
- printf("Hello world!\n");
- }
- else if(childPID ==0)
- {
- printf("Salomaaaaa i am the child");
- }
- else {
- printf("An error occured!!");
- exit(-1);
- }
- return 0;
- }
- .........................
- #include<stdio.h>
- #include<stdlib.h>
- #define _GNU_SOURCE
- #include<string.h>
- #include<unistd.h>
- void checkCommand( char* InputSepCommandTokens[] , int commandWithArgsFlag){
- if(commandWithArgsFlag==1)
- printf("You typed an argumantative command %s" , InputSepCommandTokens[0]);
- else
- printf("NO ARGUMENTS");
- }
- int main()
- {
- int commandWithArgsFlag = 0;
- char *InputCommand[10];
- char *InputSepCommandTokens[10];
- printf("Enter command Line: ");
- fgets(&InputCommand, 100, stdin);
- printf("Entered command line is:%s \n", InputCommand);
- char space[] = " ";
- char *parsedInputCommand =strtok(&InputCommand,space);
- //char* firstToken = parsedInputCommand;
- //printf("first token is:%s \n", firstToken);
- int count=0;
- InputSepCommandTokens[0] =parsedInputCommand;
- while( (parsedInputCommand) != NULL){
- printf("hi:%s \n", parsedInputCommand);
- parsedInputCommand = strtok( NULL, space );
- count++;
- InputSepCommandTokens[count] = parsedInputCommand;
- }
- //printf("\n Count is: %d \n\n ........ \n" , count);
- if(count >1) commandWithArgsFlag=1;
- int i;
- for(i=0 ; i<count ;i++){
- printf("%d token is:%s \n" , (i+1) , InputSepCommandTokens[i]);
- }
- // printf(" you just wrote:%s \n" , InputSepCommandTokens[0]);
- char * exitCheck[1] = {"exit"};
- // printf("ExitCheck is: %s\n...........\n" , exitCheck[0]);
- // printf("InputSepCommandTokens[0] is: %s\n...........\n" , InputSepCommandTokens[0]);
- if(strncmp( InputSepCommandTokens[0], exitCheck[0] , 4) == 0 ) {
- printf("\n...............PROGRAM HAS TERMINATED...................");
- abort();
- }
- else
- checkCommand(InputSepCommandTokens , commandWithArgsFlag);
- //exit(0);
- //better make this a while
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement