![]() |
I need help with C strings!
I'm trying to read strings in from a file that was inputed from the user and print them on separate lines I need to make sure that there are no non printable characters in the string. if there are non printable characters skip to the next string. A string in this should be greater than 4 characters and null terminated. I have:
Code:
#include <stdio.h> |
Re: I need help with C strings!
isprint() checks if a character is printable. It returns TRUE or FALSE.
|
Re: I need help with C strings!
thank you that helps quite a bit, now I just need to check if the string is greater than 4 characters and print it, if not call the function again and skip to the next string.
|
Re: I need help with C strings!
so I worked it out partially and I thought it should work, but my code isn't for some reason or another. here is my code as it stands.
Code:
#include <stdio.h> |
Re: I need help with C strings!
"Doesn't work" isn't much of a description. How exactly doesn't it work would be useful.
Anyway, here's one error: strcpy(str,ch); strcpy takes two strings, not a string and a char. Your logic is incorrect for testing the length of the printable string. You should collect characters until you hit a non-printable character (or EOF or the maximum size of str), THEN test the length, and display it if needed. Currently the code checks the length within the collection loop, which means the loop will terminate as soon as the length exceeds 4. |
| All times are GMT +5.5. The time now is 03:16. |