This question already has answers here:
fgets doesn't work after scanf [duplicate]
(7 answers)
how to supress warning "gets() is deprecated"? [duplicate]
(1 answer)
Why is the gets function so dangerous that it should not be used?
(13 answers)
Closed 2 years ago.
If the while loop continues "gets(purpose); just gets skipped after the first loop
while(finish==0){
printf("PASSWORD LAB EL?? WHAT IS IT??\n:");
gets(purpose);
printf("Put lth the length (LESS THAN 2048)\n:");
scanf("%d", &length);
if(length<=2048){
passwords = fopen("password.txt","a");
fprintf(passwords,"%s:\n", purpose);
for(length; length>0; length--){
int bruh = rand() % 78;
printf("%c", words[bruh]);
fprintf(passwords,"%c", words[bruh]);
finish = 1;
}
}else{
printf("TOO MUCH LAWL\n\n");
system("clear");
finish = 0;
}
}
Related
This question already has answers here:
Why the result of pow(10,2) 99 instead of 100? [duplicate]
(1 answer)
Strange behaviour of the pow function
(5 answers)
Closed 28 days ago.
when i use pow() function in Vscode editior it works properly for all digits execpt 5 and its mulitples
#include<stdio.h>
#include<math.h>
int main(){
int a = 25;
int b = pow(a,2);
printf("%d",b);
return 0;
}
This question already has answers here:
Strange behaviour of the pow function
(5 answers)
Is floating point math broken?
(31 answers)
Closed 1 year ago.
other number number raised to 2 are giving correct answer but 5,11,15... are showing 1 number less than the correct answer.
#include<stdio.h>
#include<math.h>
int main(){
int side;
printf("Enter side value \n");
scanf("%d", &side);
printf("The area is %d", (int) pow(side,2.0));
return 0;
}
This question already has answers here:
Why does printf not flush after the call unless a newline is in the format string?
(10 answers)
What is it with printf() sending output to buffer?
(3 answers)
Closed 1 year ago.
I am learning C and currently trying to understand why in the code part below the while loop is executed before the for loop!?
The code should display a 3-digit random number and then wait n seconds.
srand(time(NULL));
time_t rnd_number_length = 3;
for (int i=0; i < rnd_number_length; i++) {
printf("%d ", rand() % 10);
}
clock_t waiting_time = clock() + 5 * CLOCKS_PER_SEC;
while(clock() < waiting_time) {}
However, when I compile and run this code, the program waits first and only then displays the random digits. Why is this happening?
This question already has answers here:
Why does C allow me to call an undeclared function? [duplicate]
(1 answer)
Function assigns incorrect float value in C
(1 answer)
Closed 3 years ago.
Hey guys I was wondering why my program was just returning junk and I found out that I didn't include math.h. But why did the code even compile and run if there isn't any definition for the function ?
#include <stdio.h>
int main()
{
int ka = 0;
ka = sqrt(4);
printf("ha ist %d", ka);
system("PAUSE");
return 0;
}
This question already has answers here:
sizeof() operator in if-statement
(5 answers)
What will be the value of strlen(str)- 1 in a 'for' loop condition when str is empty?
(2 answers)
why is -1>strlen(t) true in C? [duplicate]
(3 answers)
Closed 4 years ago.
Why does the shorter string ("paid") get printed by this program?
#include <stdio.h>
int main()
{
char s[] = "paid", t[] = "paviDboss";
if ((strlen(s) - strlen(t)) > 0)
printf("%s\n", s);
else
printf("%s\n", t);
}
Return type of strlen is size_t which is an unsigned type. The result of the subtraction is also size_t and can therefore only be positive.
Just use
if(strlen(s) > strlen(t))