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

Search results for query: *

  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...
  16. DaveSinkula

    scanf() and gets() problem

    Or better yet, don't ever use gets and avoid scanf. http://www.eskimo.com/~scs/c-faq.com/stdio/scanfprobs.html http://www.eskimo.com/~scs/c-faq.com/stdio/getsvsfgets.html
  17. DaveSinkula

    casting the value of a string into int

    You don't cast a string into an int. What value would you expect "hello world" to be? Given your attempts, I might grudgingly suggest this. #include <stdio.h> int main(void) { char text[] = "hello world"; int value = *(int*)text; printf("value = %d\n", value); return 0; } /* my...
  18. DaveSinkula

    quick help, pollards rho

    Only cursory searching led me to this: http://en.wikipedia.org/wiki/Pollard's_rho_algorithm (link appears to break at apostrophe) And at a quick glance I noticed the use of absolute value. Would this produce your expected outcomes? d = gcd(abs(x-y), n);
  19. DaveSinkula

    static elements in a module

    Objects with file scope have a lifetime of the entire execution of the program, whether or not they are static. An object at file scope that is static is only visible in the current translation unit (think source code module). If an object with block scope is declared as static, it too will...
  20. DaveSinkula

    warning: integer overflow in expression

    That's about what I was coming up with. Mine was like this. #include <stdio.h> #include <stdlib.h> void error_output_quit(const char *errmessage) { puts(errmessage); exit(EXIT_FAILURE); } void *mymalloc(size_t elements, size_t size, const char *msg) { void *dynmem = malloc(elements *...

Part and Inventory Search

Back
Top