How to concatenate string and int in C?

Strings are hard work in C. The 12 is enough bytes to store the text “pre_”, the text “_suff”, a string of up to two characters (“99”) and the NULL terminator that goes on the end of C string buffers. This will tell you how to use snprintf, but I suggest a good C book!

typedef struct pointer definition

You cannot use pEDGE within the definition of the struct. You shoud do something like: You must also note that edge_item is a double pointer. You also mention that in your question. So if you use pEDGE_ITEM and you just want to have a normal pointer you should not write pEDGE_ITEM *edge_item but just pEDGE_ITEM … Read more

What is `S_ISREG()`, and what does it do?

S_ISREG() is a macro used to interpret the values in a stat-struct, as returned from the system call stat(). It evaluates to true if the argument(The st_mode member in struct stat) is a regular file. See man stat, man fstat or man inode (link to inode man page) for further details. Here’s the relevant part … Read more

How to printf long long

I’m doing a program that aproximate PI and i’m trying to use long long, but it isn’t working. Here is the code

Categories C

switch case: error: case label does not reduce to an integer constant

switch labels must be constant expressions, they have to be evaluated at compile time. If you want to branch on run-time values, you must use an if. A const-qualified variable is not a constant expression, it is merely a value you are not allowed to modify. The form of integer constant expressions is detailed in … Read more

Categories C Tags

Implementation of strtok() function

Internal implementation of strtok has already been discussed here: How does strtok() split the string into tokens in C? In your type of implementation ( calling it your type because it is quite different from the actual one), you have not allocated any memory dynamically to the local variable ‘W’. So when you return it, … Read more

error: function returns address of local variable

I’m beginner with C and I am learning on my own. I am creating the following function: I am basically trying to return an appended string, but I get the following error: “error: function returns address of local variable”, any suggestions, how to fix this?