Search:

Type: Posts; User: johnmerlino

Page 1 of 3 1 2 3

Search: Search took 0.01 seconds.

  1. What is the difference between a pointer in C and a reference in Java?

    What is the difference between a pointer in C and a reference in Java? Well, a pointer in C is a 4 byte allocation that points to an address in virtual memory. Maybe this isn't the right question for...
  2. Replies
    4
    Views
    1,842

    multidimensional arrays in C vs Java

    I am learning C and Java simultaneously and the Java docs state the following:

    "Inthe Java programming language, a multidimensional array is an arraywhose components are themselves arrays. This is...
  3. Replies
    2
    Views
    1,360

    program doesn't print data from socket

    I created a basic socket server, which listensing for incoming udp data. When I run the netcat program, I get a response:


    $ nc -luv 1732
    Connection from 10.50.11.12 port 1732 [udp/*] accepted...
  4. why does double produce trailing zeros?

    In the below function:


    double atof(char s[])
    {
    double val, power;
    int i, sign;

    for (i = 0; isspace(s[i]); i++) /* skip white space */
    ;
  5. Replies
    4
    Views
    1,163

    But if n is a negative value, n will always be...

    But if n is a negative value, n will always be less than 1 and therefore the loop will never execute, if what you say is correct, no?
  6. Replies
    4
    Views
    1,163

    How does this while loop work?

    The below function confuses me. Basically, since unsigned integers use a two's complement system, we cannot take the inverse of n before processing it, should n be negative. Because the largest...
  7. Replies
    1
    Views
    640

    hexadecimal digits greater than F?

    The example exercise in the C Programming language book states the following:

    Write the function itob(n,s,b) that converts the integer n into a base b character representation in the string s . In...
  8. Replies
    34
    Views
    15,113

    insertion sort vs shell sort

    I know the difference between insertion sort and shell sort. Insertion sort compares every single item with all the rest elements of the list, whereas shell sort uses a gap to compare items far apart...
  9. so then this must be done at compile time

    so then this must be done at compile time
  10. inserting escaped characters into char array

    Below is an extracted portion of an example exercise from the C Programming Language book:


    void escape(char * s, char * t) {
    int i, j;
    i = j = 0;

    while ( t[i] ) {
    ...
  11. Replies
    3
    Views
    3,325

    printf doesn't support format specifier for...

    printf doesn't support format specifier for clock_t?
  12. Replies
    3
    Views
    3,325

    casting clock_t to unsigned long

    I am looking at a piece of code from an exercise in the C Programming Language. It uses the clock_t data type for one of its variables. And then later when it prints the data of the variable, it does...
  13. Replies
    13
    Views
    1,332

    Yeah I removed dynamic memory allocation and used...

    Yeah I removed dynamic memory allocation and used array instead and I get same results but without memory leaks. The lesson is avoid dynamic memory at all costs, except when reading from serial...
  14. Replies
    13
    Views
    1,332

    Thus, while I can free *sensors, I cannot free...

    Thus, while I can free *sensors, I cannot free **sensors, which is the pointer to pointer.
  15. Replies
    13
    Views
    1,332

    Since sensors is a pointer to a pointer, the i-th...

    Since sensors is a pointer to a pointer, the i-th index of sensors points to *temp which points to the allocated memory on RAM. Hence, I can free that memory using the following:


    void...
  16. Replies
    13
    Views
    1,332

    This is result of valgrind: ==17724==...

    This is result of valgrind:


    ==17724== Memcheck, a memory error detector
    ==17724== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
    ==17724== Using Valgrind-3.9.0 and LibVEX;...
  17. Replies
    13
    Views
    1,332

    Do I have memory leaks?

    I wrote this program:


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


    struct sensor {
    unsigned long long int address;
  18. Replies
    3
    Views
    1,006

    check number of elements in array

    I can have at most 3 structs in array, but it could be 0,1,2 or 3 structs in array. I am trying to avoid dynamic memory allocation. I initialize sensors to 3 to reserve space for them in memory,...
  19. NULL doesn't work either, so it appears you...

    NULL doesn't work either, so it appears you cannot set 0 and NULL as values of array of structs, because if you want to check if the current index of array is NULL, there is no way to check since it...
  20. error: invalid operands to binary != (have ‘struct ’ and ‘int’)

    In the below code, when I compare a struct to 0, it gives me the error "error: invalid operands to binary != (have ‘struct <anonymous>’ and ‘int’)". The problem is I will have an array of structs and...
  21. initialize array values with 0s or assume they will be initialized to 0

    THe following:


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


    int main(int argc, char *argv[])
    {
  22. eliminating use of malloc/free when copying char arrays

    This program works as expected:


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

    typedef struct {
    unsigned long long int address;
    float ...
  23. Replies
    1
    Views
    1,090

    incorrect values in array

    I have this simple program below:


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

    typedef struct {
    unsigned long long int address;
    float ...
  24. Replies
    2
    Views
    1,166

    sizeof function and pointers

    I have this simple program:


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


    static unsigned char cmd[]={
    0x01,0x80,0x00,0x00,0x00
  25. Replies
    1
    Views
    534

    setting values to pointers

    This function below takes a pointer as an argument. What I expect to happen is, since expr++ has higher precedence than *expr, that is, the primary expression operators have higher precedence than...
Results 1 to 25 of 62
Page 1 of 3 1 2 3