w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » C » Page 1
Line break replacing first value in char array
First off, you should not be using scanf, it is vulnerable for security attacks (http://en.wikipedia.org/wiki/Scanf_format_string, see security). With the format string %s, with no width specifier, you could effectively be overwriting the next variable in memory, if the name you enter is too long. So you should make sure that the format specifier should be something such as %19s, in NAME_LEN is 20

Categories : C

C pointer arithmetic palindrome
Why do you copy your pointer in another variable? int *ptr; ptr = &numArray[0]; Just send it to you function: palindrome(numArray); And sizeof(test) give you the memory size of a pointer, it's not what you want. You have to give the size in parameter of your function. int palindrome(int *test, int size){ ... } Finally your code must look like this: #include<stdio.h> int palin

Categories : C

How to detect CLOSE_WAIT on socket in C on Linux?
From man recv: Return Value These calls return the number of bytes received, or -1 if an error occurred. The return value will be 0 when the peer has performed an orderly shutdown.

Categories : C

Go TCP read is non blocking
Readers can return partial data. From the docs, "If some data is available but not len(p) bytes, Read conventionally returns what is available instead of waiting for more." (The sample code has a possibly unrelated but important problem: it throws away errors from the Read and Write. That could mask simple problems and make them very hard to debug. If you have problems after accounting for partia

Categories : C

Find biggest cluster in a 2D array
There are more memory-efficient methods, but: you can build another matrix with the same size and initialize it to all zeroes. Let this matrix be B. Start scanning first matrix, A, with a counter N initialized to 1, and as soon as you find in A a "1" that has a "0" in B (i.e. Aij = 1, Bij = 0), put it into a list and initialize M to 0. Then until the list is empty: pop an item from the list an

Categories : C

Virtual inheritance example in C, exploiting undefined behavior?
This program does indeed invoke undefined behavior, you have a violation of strict aliasing rules here: printf("%d ", Base_get_param((Base *) d)); ^^^^^^^^^ Strict aliasing rules make it undefined behavior to access an object through a pointer of a different type, although there is an exception for char* which we are allowed to use to alias without invoking undefi

Categories : C

Count how many field of an array are full
João Reis, You're using strcmp function to compare an integer element. The correct comparison may be: if ( juiz[i].num_juiz > 0 ) njuiz++; Maybe, if you want to use strcmp, you should change your data type to char *, like this: typedef struct { char nome[30]; char num_juiz[8]; } juiz; [Edit] In addition, you should look to your set up function, to be sure your data is beeing c

Categories : C

syntax error, expecting declaration seen while compiling C code for 8051 microcontroller
Each time you use any of your macros, it declares the same variable 'x' over and over. There's also no evidence that the compiler knows what sfir or sbit orsfr16 are.

Categories : C

malloc always allocate the same address
After you allocate your memory, you store the address into the variable s. Then you overwrite that value with the address of your name variable. As a result, you will never know the allocated address, because you discarded it with the overwriting.

Categories : C


© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.