خرید بک لینک

Vote count: 0

There are three parts to this. The objective is to pass an input file to a C-Programm, have it run through the input, create an output and compare that to the correct_output.data.

Here is the Shell I was given:

#!/bin/sh
input_file="input.data"
output_file="output.data"
correct_output_file="output_correct.data"
while read line do  echo $line | ./Prak1A3 done < $input_file > output.tmp
sed -i 's/Geben Sie einen Satz ein: Eingegeben: //g' output.tmp cat     output.tmp > $output_file
rm output.tmp
diff -u -s $output_file $correct_output_file

Here is the C-Programm

#include <stdio.h>
#include <stdlib.h>

int main(void) {
//char * input="this is a test sentence";
//int index;
int charCount;
int wordCount;
char currentChar;
int isInWord=0;



charCount = 0;
wordCount = 1;

currentChar = getchar();

while(currentChar != 'n'){

    if(getchar() == ' ' || getchar() == 't'){
        isInWord = 0;

    }else if( getchar()!='t'||getchar()!=' '){
        charCount++;
        if(isInWord == 0){
            wordCount++;
            isInWord=1;
        }
    }
currentChar = getchar();

printf("%d Wörter, %d Zeichen  n", wordCount, charCount);
}
}

The Input File:

Ein normaler Satz. Ein Satz mit vielen Leerzeichen. Tabs und
Leerzeichen kombiniert. Ein Tab nach dem Satz.
Leerer Start. Tabs voe und hinten.

Correct Output File

3 Wörter, 16 Zeichen 5 Wörter, 28 Zeichen 4 Wörter, 29 Zeichen 5 Wörter, 18 Zeichen 0 Wörter, 0 Zeichen 2 Wörter, 12 Zeichen 4 Wörter, 19 Zeichen

Right now I am creating an executable in terminal with gcc -o prak Prak1A3.c However, I am not seeing any use of the shell-script and if I run the exectuable it launches another terminal window and waits for input from my keyboard. Any help or pointers would be appreciated.

asked 42 secs ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 10 اسفند 1394 ساعت: 15:53

صفحه بندی