Questions tagged [printf]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
120 views

Tideman, my tests work but check50 says there is an error

When I test my code I get the correct output but check50 shows errors in print_winner function. :( print_winner prints winner of election when one candidate wins over all others print_winner did not ...
0
votes
1answer
28 views

speller- tried using printf to debug -printf not working

I'm sure I'll soon feel stupid to ask this question. I'm trying to use printf() to see how far along my code got. But it wasn't printing anything even when I added printf to the first line in main(). ...
0
votes
2answers
39 views

PS1, Cash Question. Error when printing results of roundI() function

I am trying to print out the results of the round() function. #include <stdio.h> #include <math.h> int main(void){ float change = 4.2; //want change for $4.2 printf("rounded %i",...
0
votes
1answer
15 views

Help in linked datastructure

I have tried to rewrite what David said in the lekture, but cant print out my values and do not know how. I have tried to make a for look but didnt work either. #include <stdlib.h> #...
0
votes
1answer
67 views

Why removing a printf function messes up with my code? CS50 pset1 cash greedy challenge

I finished the challenge and my first C code worked apparently well, returning each time the correct minimum number of coins needed for change. Then when I tried to "clean it up" a bit and remove a ...
1
vote
2answers
42 views

addition operation difference using printf in c

I came across the following unexpected behaviour while working on pset2 does any body have any idea why this is happening in the following code, at the 9th line. #include <cs50.h> #include <...
0
votes
1answer
31 views

Printing a character times a variable

I have a question about that I would greatly appreciate if someone with knowledge could answer. In C, is it valid to print a character times a variable? For example (spaces and stories are both ...
0
votes
1answer
226 views

String being replaced by garbage before being printed

I have this code: #include <cs50.h> #include <stdio.h> #include <string.h> string increment_str(); int main() { string s = increment_str("xyz"); printf("String: %s\n", s); }...
0
votes
1answer
58 views

Vigenere Pset2 ciphertext question + others

(Main question- need help on this for code to work! highlighted in screenshot.) My PSET2 code works fine up until asking the user to input plaintext, but becomes funky and outputs blank spaces as the ...
0
votes
1answer
130 views

PSET 2 Caesar ciphertext Printf help

I am having issues with printf in Caesar Pset 2, as can be seen through how the program is being executed in the terminal window. I have highlighted in the screenshot where I believe the problem lies. ...
0
votes
1answer
1k views

The question mark (????) example | Mario

From the third lecture I can't understand the following: Here is the code example: #include <stdio.h> int main(void) { for (int i = 0; i < 4; i++) { printf("?"); ...
0
votes
1answer
238 views

Pset2 Crack - Including printf causes passwords I am generating to change

I'm trying to incrementally solve the crack problem by doing the following: Crack one character password "a" with salt of "50" (hash: 50OqznXGVcOJU) Crack two character password "aa" with salt of "50"...
0
votes
0answers
56 views

Printf prints newline character instead of string in Pset5

I'm working on the Speller program in Pset5. As always, i'm using a modular approach to construct all the required constituent functions one by one. However, something quite odd is happening in my ...
0
votes
0answers
60 views

2017 mario.c trailing whitespace for height < 23

I have been trying to fix the whitespace error generated with my code: int main() { int height; do { printf("Height: "); height = get_int(); } while (height < 0 || ...
0
votes
2answers
2k views

CS50 week 2 Caesar(cipher printf question)

#include <stdio.h> #include <stdlib.h> #include <cs50.h> #include <ctype.h> #include <string.h> int main( int argc,string argv[]){ int k; if (argc == 2) { ...
0
votes
1answer
76 views

Puzzled by Pset3 - find less confortable- sorting output

I just checked my code for Pset3 finds less confortable and it works but I am puzzled by some of the printf I put to debug my code. I put this just at the end of my sorting function: printf("%i %...
0
votes
1answer
38 views

Printing text after GetInt()

I was wondering if there was a way to do something like the following Enter the coefficients in order __ * x^3 Where the __ is where the user will be prompted for input. However, I want the *x^3 ...
0
votes
2answers
221 views

Caesar cipher print statements all running together - C

My code compiles but check 50 tests print errors like this: :( encrypts "barfoo" as "yxocll" using 23 as key \ expected output, but not "barfoo\nciphertext:yxocll" I've tried every modification I ...
0
votes
1answer
607 views

trail of strange characters after printing character array

I wrote my vigenere cipher program and everything works fine, but when I run check50 I get the following error:(p is the plaintext string) char c[strlen(p)]; for(int i = 0, j = 0, l = strlen(p), n = ...
0
votes
1answer
38 views

I have written this code for vigenere and it is giving 02 errors

Here is my code it is giving two error described below. on line 34 key[j]=tolower (argv[j])-97; I can't understand what's the error. on line 50 and 55 same problem printf("%c",((p[k]-65)+(key[c%klen])...
0
votes
1answer
580 views

what does %d or %i do?

I have had this question since I start this course. what does %d or %i or %f do ? for example, printf("%i/n", n); what I found is it is modulo as operator. It seems like substitute symbol to print ...
0
votes
1answer
53 views

Greedy not printing

So when I run my code it asks for the amount but then it doesn't print the number of coins... Help! #include <stdio.h> #include <cs50.h> #include <math.h> int main(void) { /* ...
2
votes
2answers
89 views

Why the printf function is able to print 28 decimal digits, if the float has only 24-bits mantissa?

What is exactly printing in the example in the week 2 lecture: float f = 1.0/10.0; printf("%.28f\n", f); // prints the following: 0.1000000014901161193847656250 I mean, if float is represented on ...
1
vote
1answer
307 views

How do I print the values of variables?

How do I print the values of a variable?
0
votes
1answer
99 views

pset 1 Mario - clang error - printf syntax error? won't allow /n at end of printf line - error code

I'm a complete newbie to code writing. I'm working on the mario pyramid project. I'm writing the following lines of code and when I run MAKE I get an error in the compiler. here is the code I've ...
0
votes
1answer
2k views

printf is changing string contents

I finished PSet2 with all the correct results, but I'm trying to figure out why I had to change some of my code in initials.c to make it work properly. The original code is as follows: #include <...
0
votes
1answer
69 views

segfaults and delayed printf commands while using GWindow in loop

printf("%c.\n", (getText(precrmo_menu[3]))[0]); char input[3]; input[0] = (getText(precrmo_menu[3]))[0]; printf("we lived"); if (strcmp(input, "") != 0 && !isblank(input) && ...
0
votes
1answer
563 views

what (%s) mean in printf in c

In printf("abdooo,%s\n ") what does %s mean ? And what will happen if I delete it?
0
votes
1answer
23 views

Why “the eight such byte” would be bracket four in printf(“%c”, s[4]) ? -lecture 2

In lecture 2 (49'09''), speaking about s[i] (like in printf("%c", s[i]) ), David says: "So if you want to get at the eighth such byte, which in this loop would be bracket zero, bracket one, bracket ...
1
vote
1answer
403 views

fifteen.c : printf() not printing anything to the screen

To check the execution sequence of the code, I have added printf statement just below the main(): int main(int argc, string argv[]) { // greet player printf("abc \n"); greet(); ...
2
votes
1answer
2k views

How does printf and scanf works behind the scene?

How do printf and scanf actually works behind the scene ??
5
votes
5answers
27k views

Can you print more than one char in C by using “x” * 5 like you can in Python?

In Python you can have a print statement print out a number of the same char by using print("X" * 5) which will give you XXXXX. Can this be done in C with printf?
3
votes
2answers
215 views

How does a person make a character print more than once?

I've watched all the videos for pset1 and I cannot figure out how to make the space or indention print out more than once. Can anybody tell me where I'm supposed to find that kind of information? or ...