Why is int to float conversion failing in printf?

Advertisements When using a int to float implicit conversion, it fails with printf() #include <stdio.h> int main(int argc, char **argv) { float s = 10.0; printf("%f %f %f %f\n", s, 0, s, 0); return 0; } when compiled with gcc -g scale.c -o scale it does output garbage ./scale 10.000000 10.000000 10.000000 -5486124068793688683255936251187209270074392635932332070112001988456197381759672947165175699536362793613284725337872111744958183862744647903224103718245670299614498700710006264535590197791934024641512541262359795191593953928908168990292758500391456212260452596575509589842140073806143686060649302051520512.000000 If I… Read More Why is int to float conversion failing in printf?

GCC does not recognize escape character '\' on multi-line input

Advertisements The below will raise compilation warning warning: unknown conversion type character ‘w’ in format [-Wformat=] on a new version of gcc: gcc (Debian 12.2.0-14) 12.2.0 #include <stdio.h> int main() { char query[4096]; snprintf(query, sizeof(query), "SELECT e.expression_id, e.name, e.channel, e.subsidiary_of, ds.input_channel FROM expression e " " JOIN shoe s ON s.shoe_id = e.shoe_id JOIN device_serial… Read More GCC does not recognize escape character '\' on multi-line input

The scanf to get "name" skips itself when i execute it. What changes do I make inorder for it to no do that?

Advertisements #include <stdio.h> int b; int main() { int a, c; printf("Enter the number of students \n"); scanf("%d", &a); struct studinfo{ char name[50]; int roll; float marks; }; struct studinfo s[10]; for(int i = 0; i <= a; i++) { printf("Enter the Name :\n"); scanf("%[^\n]s", s[i].name); //THIS ONE HERE printf("\n"); printf("Enter the roll no. \n");… Read More The scanf to get "name" skips itself when i execute it. What changes do I make inorder for it to no do that?

sscanf does not work properly for eight and nine with leading zero

Advertisements I’ve been trying to scan integers with sscanf() from strings with leading zeros (e.g. ’03’). However, it works fine but only until ’07’. Starting with ’08’, the strings will be read as 0. Below you’ll find my code and the output. Thank you for your help! #include <stdio.h> #include <stdlib.h> int main() { char… Read More sscanf does not work properly for eight and nine with leading zero