Reputation: 23
This is about a super small issue but I can't seem to get a new line started as my book is showing me. (C Programming An absolute beginners guide by Perry and Miller) I'll paste my code below.
The last word, said, is supposed to be on a separate line but for some reason the \n there isn't working. To be fair this book is based on Code::Blocks 10.05 so it could be a formatting issue?
// Absolute Beginner's Guide to C, 3rd Edition
// Chapter 4 Example 1--Chapter4ex3.c
#include <stdio.h>
main()
{
/* These three lines show you how to use the most popular Escape
Sequences */
printf("Column A\tColumn B\tColumn C");
printf("\nMy Computer\'s Beep Sounds Like This: \a!\n");
printf("\"Letz\bs fix that typo and then show the backslash ");
printf("character \\\" she said\n");
return 0;
}
Upvotes: 2
Views: 274
Reputation: 844
Change
printf("character \\\" she said\n");
to
printf("character \\\" she \n said");
Actually, \n is the escape sequence for next line. Whenever the \n is displayed, it takes the cursor to the next line. So if you want to put the word said in a separate line, you must take the cursor to the next line before displaying it, which means you must print a \n before printing the word said.
Upvotes: 1
Reputation: 343
Whenever you need something on a new line, you have to add \n just before that. So if you want 'said' on a new line, then add \n before 'said'. Like this printf("character \\\" she \nsaid");
Upvotes: 4