C user input sporadic invalid results

Advertisements Coding in C, I’m having an issue with user input. Sometimes, the input works and sometimes it doesn’t. Example run output from terminal: dennis@MBP2021 Encryption % make cc Gronsfeld_Cipher.c /Users/dennis/Documents/C/programs/DJSlibrary/cs50.c -o cipher dennis@MBP2021 Encryption % ./cipher Please enter line to be encoded: This, however, is not the time. You entered: This, however, is not… Read More C user input sporadic invalid results

invalid characters happens by using truncate(0) in python

Advertisements I used truncate(0) in python to overwrite data on my file. Part of the code is like this: l=f.readlines() f.truncate(0) for w in l: data=w.split() if 105==int(data[0]): f.write(‘%s %s\n’%((str(data[0]),str(np.mean(b))))) else: f.write(‘%s %s\n’%((str(data[0]),(data[1])))) The code works fine and output is correct, but when I open the output file (which is in txt format) I got… Read More invalid characters happens by using truncate(0) in python