How to check for NULL characters in file ?
1)
Code:
FILE *fp; The code within Code:
if (buf != NULL) is being executed. How do I check if a file contains only NULL characters? ( file length > 0, file contents = NULL ) 2) How do I ensure ^M characters are not printed at the end of each line of the file I write into? Tried appending Carriage return (13) at the end of each line. Not working...?? Thanks |
In vi type (in escape mode)
:set list This will show any ^M characters and line breaks tabs etc. If you run dos2unix filename newfilename it should get rid of the ^M characters. |
Thanks for the reply.
I know how to get rid of ^M from vi. I would like to programatically get rid of it,when I am printing to a file using fprintf(...)? Thanks |
You could use a perl script:
Code:
#!/usr/bin/perl -w |
Thanks for the reply.
This is a small peice of code,I posted from a large C program with a number of files & the program would continue to execute after the mentioned piece of code is executed. So I wouldn't be able to use external programs like perl,awk,sed,etc. I need to do this in plain old C :) Thnks |
Code:
#include <stdio.h> |
Code:
FILE *fp; To check if there is one or more null characters, I would use strlen(buf). If that's smaller than the length of the file, you have NULL characteres. With regards to ^M, use strchr() to search for it (I always have to think which one is which, probably search for '\r'). PS you can also iterate through buf to find NULL in which case you must use Code:
if(*buf != '\0') |
All times are GMT -5. The time now is 06:18 PM. |