2014-03-01 2 views
0

아래 쉘 프로그램으로 바꾸려는 토크 나이저가 있습니다. 나는이 프로그램이 모든 쉘 명령을 사용하도록 설정되어 있지는 않지만 현재 작업중인 디렉토리를 인쇄하는 데 문제가 있음을 알기에 막 시작했습니다. 나는 아래에있는 내 코드가 표시됩니다 :현재 작업 디렉토리 인쇄하기

#include <ctype.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <unistd.h> 
#include <errno.h> 
int main() 
{ 
pid_t pid; 
char cwd[1000]; 
if (getcwd, sizeof(cwd) != NULL) 
{ 
    fprintf(stdout, "Current working dir: %s\n"); 
    return 0; 
} 
printf("Please enter a string\n"); 
int ch = fgetc(stdin); 
while (ch != EOF) 
{ 
    pid = fork(); 
    if (pid == 0) 
    { 
     printf("Child Working"); 

    } 
    else 
     printf("Child not working"); 
while (isspace(ch)) 
{ 

    // If only 1 line of input allowed, then add 
    if (ch == '\n') return 0;; 

    ch = fgetc(stdin); 
} 
if (ch != EOF) 
    { 
    do 
    { 
    fputc(ch, stdout); 
    ch = fgetc(stdin); 
    } 
    while (ch != EOF && !isspace(ch)); 
    fputc('\n', stdout); 
    } 
    } 
    return 0; 
} 

내가 지금까지 무엇입니까 출력은 아래 화면 캡처에 있습니다

enter image description here

+0

또한 내 포크 프로세스는 단지 다른 쉘 명령을 처리 할 수있는 설정, 즉 비트가 혼란 죄송 경우 – user3358064

답변

1

변화

if (getcwd, sizeof(cwd) != NULL) 

에 :

if (getcwd(cwd, sizeof(cwd)) != NULL) 

fprintf(stdout, "Current working dir: %s\n"); 

에 :

printf("Current working dir: %s\n", cwd); 
+0

와우 감사합니다, 나는 기분 사과 간단한 오류로 시간 낭비 – user3358064

+0

@ user3358064 시간 낭비가 아닙니다. 대답하는 것은 그의 결정이었습니다. 이것은이 사이트가있는 것입니다 :) –

관련 문제