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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recent content by DaveSinkula

  1. DaveSinkula

    How do I read a csv file with missing values

    I avoid strtok when dealing with empty fields. A few reasons why, and an alternative: #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { static const char filename[] = "file.csv"; /* the name of a file to open */ FILE *file = fopen(filename, "r"); /* try to open...
  2. DaveSinkula

    Possible syntax error in C module

    Do you have a missing semicolon in code prior to this?
  3. DaveSinkula

    Newbie Question: How to count pipes in a string / output to file

    Whatever is appropriate. One option: strncat: http://c-faq.com/lib/strncpy.html
  4. DaveSinkula

    Newbie Question: How to count pipes in a string / output to file

    ...and that it does not necessarily null terminate the destination string. But as for "always use strncpy instead of...", I'd say, "No, avoid strncpy as well.
  5. DaveSinkula

    Newbie Question: How to count pipes in a string / output to file

    Now, what's the issue with strncpy that you didn't mention -- which also can be dangerous?
  6. DaveSinkula

    How would you create a random string of data

    #include <stdio.h> #include <stdlib.h> #include <time.h> char *rand_str(char *dst, int size) { static const char text[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int i, len = rand() % (size - 1); for ( i = 0; i < len; ++i ) {...
  7. DaveSinkula

    sscanf seems o loop forever

    Perhaps something like this. #include <stdio.h> int main() { const char filename[] = "file.txt"; FILE *file = fopen(filename, "r"); if ( file ) { char dbuf[100]; while ( fgets(dbuf, sizeof dbuf, file) != NULL ) { unsigned int ch; int n...
  8. DaveSinkula

    Passing an array as function paramater problem.

    I think you were closer the first time.
  9. DaveSinkula

    Printing Char Strings as Hexadecimal

    Very similar to code already posted: #include <stdio.h> typedef struct { unsigned char var1[6]; unsigned char var2[6]; } MY_STRUCT; int main(void) { MY_STRUCT my_struct = { {0x00,0x06,0x29,0x77,0xB1,0xAD}, {0x00,0x06,0x29,0x77,0xB1,0xAD}, }; size_t i; for ( i...
  10. DaveSinkula

    Tracing a rounding error

    http://en.wikipedia.org/wiki/Floating_point#Peculiar_properties_of_floating_point_arithmetic
  11. DaveSinkula

    Comparing double type numbers

    http://c-faq.com/fp/fpequal.html
  12. DaveSinkula

    Dynamic input of strings

    line = realloc(line,linesize*sizeof(*line)); http://cboard.cprogramming.com/showthread.php?p=367853#post367853
  13. DaveSinkula

    &quot;Proper&quot; way to declare functions

    I generally go with #2, but only have the "public" functions in the header; any "private" functions are then static to the module. What is an example of "all of the information contained within the function's header file"? Generally it should only be necessary data types and such: declarations...
  14. DaveSinkula

    Pointer/struct syntax

    http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1047673478&id=1043284351 p = malloc ( n * sizeof *p );
  15. DaveSinkula

    scanf() and gets() problem

    NOOOOOOoooo!!! [The evil seed begins to grow.] Use a buffer that ought to be "big enough". Use fgets to read input as a string. Examine the string to see if a newline is at the end. If so, there may be excess data. If not, possibly trim the newline. Or do other conversions, if necessary, using...

Part and Inventory Search

Back
Top