Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does anyone know? 1

Status
Not open for further replies.

jarice1978

Programmer
Dec 29, 2003
3
US
I am looking for some links to sites that have sample C code.
More specifically I need to write a program that reads a fixed length file and writes the output as a comma delimited file. I will be using structs to read from...

However, the sites would help out now and for future reference...

Thanks,


JAR
 
> I will be using structs to read from...
If you're referring to your previous post on reading a text file into fixed length records, then I would advise against that approach.

As previously noted, structs can be padded, which can throw off all your size calculations.

Code:
int main ( ) {
    char buff[BUFSIZ];
    while ( fgets( buff, BUFSIZ, stdin ) != NULL ) {
        printf( "%.4s,%.6s,%s", &buff[0], &buff[4], &buff[10] );
    }
    return 0;
}
Just replace stdin with the FILE *fp of the file you opened.

This is an example input and output
Code:
1234abcdef!!@@
1234,abcdef,!!@@

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top