I implemented the music program in pc and I omitted the cs50.h library since I work offline most of the time. Everything's fine actually my code did not give me error messages and it compiled successfully. However, when execute the program using test.wav.. I notice that the output .wav file doesn't play or read all the notes from my .txt file. The same thing is true if i try to output a bday.wav file and any other song.. It doesn't read and play all the notes.. Can someone help me on this? in get_string implementation.. i replace it with scanf.Here is an exerpt of my code in sythesize

char* line;
line = (char*)malloc(1000*sizeof(char));

// Expect notes from user until EOF
while (true)
    // Expect note

    scanf("%s", line);

    if(scanf("%s", line) == EOF)
    //if(*line == EOF)
  • Hi Gibson, welcome to Stack Exchange. It looks as if you are trying to post several questions at the same time. Could you please post them as separate questions? – Peter Pesch Oct 13 '18 at 6:33

The part of this question which is easiest to understand is the part about your implementation of get_string().

  • The function get_string{} is supposed to return as soon as the user inputs a string.
  • However, your version does not check the input, it only checks for EOF - and only when that's the only input ...

Apart from that:

scanf("%s", line);

if(scanf("%s", line) == EOF)

That part of you code: - first tries to read some input and store it in line - and then immediately tries to overwrite that with some new input.

If you really insist on writing get_string() yourself, I suggest you test that part in a separate program until it works as expected.

Or try some way to use cs50.h ...

Finally, to quote Cliff B:

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

| improve this answer | |
  • Thank you so much. Yes that's where the error is i think. I also tried to use if(line == NULL)// checks for EOF It also compiled successfully but when i execute the ./synthesize bday.wav < bday.txt it gives me an error that says load of null pointer of type 'char' UndefinedBehaviorSanitizer:DEADLYSIGNAL – Gibson Oct 13 '18 at 7:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .