×

C Programs

C Basic & Conditional Programs

C Looping Programs

C String Programs

C Miscellaneous Programs

Error: Invalid escape sequence in C | Common C program Errors

Here, we will learn how we get the wrong output after using invalid escape sequence in C language.
By IncludeHelp Last updated : March 10, 2024

Error: Invalid escape sequence in C

Sometimes, while writing Escape Sequences in C program, we mistakenly typed an invalid escape sequence, which does not give any error but does not give the expected result.

For example, if we want to print a "new line" between two words in a text and mistakenly typed \m instead of \n.

Example

#include <stdio.h>

int main(void) {
	
	printf("Hello world\mHow are you?");
	
	return 0;
}

Output

    Hello worldmHow are you?

We wanted to print "Hello world" and "How are you?" in separate lines but there is an invalid escape sequence \m. Thus, the result is "Hello worldmHow are you?".

How to fix "Invalid escape sequence in C" error

To fix this and such errors, you should know about all escape sequences and use them properly.

Read: Escape sequences in C

Correct Code

#include <stdio.h>

int main(void) {
	
	printf("Hello world\nHow are you?");
	
	return 0;
}

Output

    Hello world
    How are you?

C Common Errors Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.