1

I have a C program and I need to test program reads stdin when called like this

./program

Now I have to write a bash script that will send it an increassingly long string! For example first a, then aa, aaa, aaaa and so on. How can I do this?

I already found a nice way to construct a string (I iterate over string_length):

string=(head -c string_length < /dev/zero | tr '\0' '\141')

but how do I pass it to my program using stdin?

1 Answer 1

2

This example might be a hint.

//test.c
#include <stdio.h>

int main()
{
    char s[100];
    scanf("%s", s);
    printf("string: %s\n", s);
    return 0;
}

$ gcc test.c -o test
$ echo -n goodluck | ./test
string: goodluck
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.