Creating a new directory in C

Look at stat for checking if the directory exists, And mkdir, to create a directory. You can see the manual of these functions with the man 2 stat and man 2 mkdir commands.

How to convert integer to string in C?

Use sprintf(): All numbers that are representable by int will fit in a 12-char-array without overflow, unless your compiler is somehow using more than 32-bits for int. When using numbers with greater bitsize, e.g. long with most 64-bit compilers, you need to increase the array size—at least 21 characters for 64-bit types.

C: linker command failed with exit code 1

You have the following line of code: Inside the main function. There are 2 major problems with this. Function declarations cannot appear inside of another function. The line I quoted needs to appear outside of your main function as follows:int lookup(…..) //code here int main(…) { //more code here } Even though you declare the … Read more

Examples of good gotos in C or C++

Heres one trick I’ve heard of people using. I’ve never seen it in the wild though. And it only applies to C because C++ has RAII to do this more idiomatically.

Going through a text file line by line in C

So many problems in so few lines. I probably forget some: argv[0] is the program name, not the first argument; if you want to read in a variable, you have to allocate its memory one never loops on feof, one loops on an IO function until it fails, feof then serves to determinate the reason … Read more

lvalue required as left operand of assignment

You need to compare, not assign: Because you want to check if the result of strcmp(“hello”, “hello”) equals to 0. About the error: lvalue required as left operand of assignment lvalue means an assignable value (variable), and in assignment the left value to the = has to be lvalue (pretty clear). Both function results and constants are not assignable (rvalues), so they are rvalues. … Read more

Reading \r (carriage return) vs \n (newline) from console with getc?

\n is the newline character, while \r is the carriage return. They differ in what uses them. Windows uses \r\n to signify the enter key was pressed, while Linux and Unix use \n to signify that the enter key was pressed. Thus, I’d always use \n because it’s used by all; and if (x == ‘\n’) is the proper way to test character equality.

Is “argv[0] = name-of-executable” an accepted standard or just a common convention?

Guesswork (even educated guesswork) is fun but you really need to go to the standards documents to be sure. For example, ISO C11 states (my emphasis): If the value of argc is greater than zero, the string pointed to by argv[0] represents the program name; argv[0][0] shall be the null character if the program name is not available from the host environment. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)