I’m having this problem.
char buffer[100];
buffer[0] = "\n";
For some reason, the following statement is true
buffer[0] == 'T'
When it should be the “\n” ascii. Why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try
*buffer[0] = '\n'. I think that would give you the desired result, as it ischaryou are assigning notstring. Forstringuse double quotes and forcharsingle quote.As rightly pointed in the comment
buffer[0]is char pointer, so first it needs to be allocated memory too.callocwould be a better choice here as it is going to assign default 0 values whereasmallocwill just allocate space having garbage values.