IT, Programming, & Web Development › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 2: [Arrays] – Functions, Variable and Scope, Debugging, Arrays, and Command Line Arguments › How to get $ in a new line
Tagged: \n, Caesar project, newline
- This topic is empty.
-
AuthorPosts
-
January 26, 2022 at 5:54 am #167
While working on Caesar project, this is my current code:
[dm_code_snippet background=”yes” background-mobile=”no” slim=”yes” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
#include<stdio.h> #include<cs50.h> #include<string.h> #include<ctype.h> int main(void) { string name = get_string("Enter: "); printf("Entered text by user: %s\n", name); int n = strlen(name); printf("length of entered text: %i\n", n); int key = get_int("enter key: "); char newuppercase_array[n]; for (int i = 0; i < n; i++) { if (isupper(name[i])) { newuppercase_array[i] = ((((name[i] - 65) + key)%26) + 65); } else { newuppercase_array[i] = name[i]; } printf("%c",newuppercase_array[i]); } }
[/dm_code_snippet]
Now, how to get $ prompt in a new line. I tried with this but not successful:
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”yes” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
printf("%c\n",newuppercase_array[i]);
[/dm_code_snippet]
Is there is a need to create a new string variable/array and then use printf?
Reply
Outside your loop simply do:
[dm_code_snippet background=”yes” background-mobile=”no” slim=”yes” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
printf("\n");
[/dm_code_snippet]
print newline after for loop ends.
[learn_press_profile]
-
AuthorPosts
- You must be logged in to reply to this topic.