- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
CS50x threads to aide as a supplementary resource › 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
While working on Caesar project, this is my current code:
#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))
{
newuppercase_array = ((((name - 65) + key)%26) + 65);
}
else
{
newuppercase_array = name;
}
printf("%c",newuppercase_array);
}
}
Now, how to get $ prompt in a new line. I tried with this but not successful:
printf("%c\n",newuppercase_array);
Is there is a need to create a new string variable/array and then use printf?
Reply
Outside your loop simply do:
printf("\n");
print newline after for loop ends.
[learn_press_profile]