Search:

Type: Posts; User: saeculum

Search: Search took 0.01 seconds.

  1. Replies
    8
    Views
    3,147

    EOF is defined as -1 (in stdio.h), which is...

    EOF is defined as -1 (in stdio.h), which is nonzero and aids in the reading of the code.


    That's true, apologies it was added in a rush. The use of feof is fine there, though removing it and...
  2. Replies
    8
    Views
    3,147

    #include #include int...

    #include <stdio.h>
    #include <string.h>

    int main( void ) {
    char string[30];

    FILE *fileptr = fopen("example.txt","r");

    while( feof(fileptr) != EOF ) {
    if(...
  3. Replies
    13
    Views
    1,282

    There's a rule of thumb, which states that for...

    There's a rule of thumb, which states that for each call to malloc/calloc, there should be a corresponding free call.

    It looks fine.

    Also, if you're running Linux, you might like to use...
  4. Replies
    2
    Views
    1,286

    Ahh, why didn't I catch that, nice one! I'd need...

    Ahh, why didn't I catch that, nice one! I'd need to flush stdout to ensure it would print before the perror call, but you're right with the stderr, I should be using it to print error messages.
    ...
  5. Replies
    2
    Views
    1,286

    Non-sequential printing

    Hi, I'm having issues with perror(), it's printing before an fprintf call which occurs before it. The tokptr variable is correct, I'm also aware that errno should be saved if perror isn't ocurring...
  6. Replies
    13
    Views
    1,282

    It depends on how you malloc() them. You can...

    It depends on how you malloc() them. You can allocate the array as contiguous memory if that's needed, or just allocate all willy-nilly like.

    http://c-faq.com/aryptr/dynmuldimary.html
  7. Replies
    33
    Views
    3,414

    Hi, the while loop needs to have: power =...

    Hi, the while loop needs to have:


    power = power * x;
    statement in as well. Otherwise, you'll just find x^1.

    The specs seem a little out of order.

    a. input integer variable x with scanf...
  8. Thread: help

    by saeculum
    Replies
    4
    Views
    1,321

    While x is greater than 0, you'd divide x by 2...

    While x is greater than 0, you'd divide x by 2 (assigning the result back to x), the number of times it does this division is equal to the number of bits required to represent the number.

    Of...
  9. Replies
    3
    Views
    1,947

    Hey. char *dir_path; ... dir_path =...

    Hey.


    char *dir_path;
    ...
    dir_path = strcat(dir,"/");
    dir_path = strcat(dir_path,dp->d_name);
    You've declared a pointer to an array that current has no space allocated. You're trying to...
  10. Replies
    1
    Views
    1,983

    Storing Code Snippets

    Hi. I've just reintroduced myself to C with a nice application, I'd like to save some of the snippets and I'm wondering how other people do this - a member here mentioned a backup of their c library...
  11. Replies
    4
    Views
    1,525

    strtok or strsep will do this though strsep...

    strtok or strsep will do this though strsep doesn't conform to C99 standard. A space ' ' delimiter would be used.

    http://www.manpagez.com/man/3/strtok/
  12. Replies
    16
    Views
    3,609

    If you want to convert the integer to a...

    If you want to convert the integer to a hexadecimal value you can use sprintf or snprintf.

    The compiler errors tell you where to look.

    Line 57, it's a do while loop.


    do
    {
    dummy =...
  13. Hi matsp, thanks for your comments. I've read...

    Hi matsp, thanks for your comments. I've read through and used clock_getres(), it wasn't defined as was thought. Thanks for the tipoff about clock_getres()! Quite useful.

    The application at this...
  14. Replies
    5
    Views
    1,879

    #include #include #include...

    #include <stdio.h>
    #include <math.h>
    #include <string.h>

    int main( void ) {
    char *bitstring = "10.1101";
    int decimalPoint = 0; /* Location of decimal */
    int i = 0; ...
  15. Replies
    4
    Views
    5,172

    Hi, I modified your program slightly, inputs[i]...

    Hi, I modified your program slightly, inputs[i] is no longer assigned a value within the loop for obvious reasons (you'll see in a second).



    #include <stdio.h>

    int main() {
    int gates;
    ...
  16. Portable method of accessing CPU time for given process

    Hi, I'm using the following code to print the duration of a program. I'm using clock(), or if available clock_gettime() with CLOCK_PROCESS_CPUTIME_ID.



    #ifdef _POSIX_CPUTIME
    #ifdef...
  17. Replies
    2
    Views
    1,335

    It's a little unclear as to what you want, here's...

    It's a little unclear as to what you want, here's a shot though.



    if( freopen(argv[1], "a", stdout) == NULL ) {
    fprintf(stdout,"Error with freopen(): ");
    perror("");
    ...
  18. You've not mentioned whether you've been testing...

    You've not mentioned whether you've been testing the return value for fgets(). If there's a read error it should return a null pointer. I'd probably start off by checking that.
  19. Replies
    3
    Views
    2,496

    Hi, thanks for the replies. Finally found some...

    Hi, thanks for the replies. Finally found some time to go through the program in more detail. As it turns out, although the convention I was using to allocate memory to the 2-dimensional arrays...
  20. Replies
    3
    Views
    2,496

    Structure of structures + linked list

    Hi. I'm using a structure of structures, inside of which is a linked list, to pass information through a program. Unfortunately, occasionally it will have a segmentation fault.

    Though more...
  21. Replies
    3
    Views
    1,627

    If you want to code it in C, check out UNP (Unix...

    If you want to code it in C, check out UNP (Unix Network Programming). There's basic examples on writing servers and clients, and it wouldn't take much common sense to adapt them to your needs.
Results 1 to 21 of 25