C: scanf to array

if (array[0]=1) should be if (array[0]==1). The same with else if (array[0]=2). Note that the expression of the assignment returns the assigned value, in this case if (array[0]=1) will be always true, that’s why the code below the if-statement will be always executed if you don’t change the = to ==. = is the assignment … Read more

Categories C Tags

char array not assignable

Yes char arrays are not assignable just as all arrays aren’t. You should use strcpy for example and so on. Also, you don’t need to declare char class[30]; the longest string I see in your code is “undefined” so should be ok, 9 characters of “undefined” + 1 null terminating byte ‘\0’. And you should … Read more

Reaching EOF with fgets

I’m writing a function that perform some authentications actions. I have a file with all the user_id:password:flag couples structured like this: Users.txt user_123:a1b2:0 user_124:a2b1:1 user_125:a2b2:2 This is the code: How can I manage the EOF reaching? I saw that when EOF is reached fgets doesn’t edits anymore the usr_psw_line but neither returns a NULL pointer. … Read more

Simple C scanf does not work? [duplicate]

When reading input using scanf, the input is read after the return key is pressed but the newline generated by the return key is not consumed by scanf, which means the next time you read a char from standard input there will be a newline ready to be read. One way to avoid is to … Read more

Return a `struct` from a function in C

You can return a structure from a function (or use the = operator) without any problems. It’s a well-defined part of the language. The only problem with struct b = a is that you didn’t provide a complete type. struct MyObj b = a will work just fine. You can pass structures to functions as … Read more

Categories C Tags

Math constant PI value in C

Calculating PI value is one of the complex problem and wikipedia talks about the approximations done for it and says it’s difficult to calculate PI accurately. How does C calculate PI? Does it calculate it every time or is it using a less accurate fixed value?

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