Danila White
Pls I'm waiting for your feedbacks. 🙏
maybe this will help you https://codeforces.com/blog/entry/61587
B220059_Subhra_Bhanja
//converter - temperature, weight, height #include<stdio.h> int main() { printf("Type the number: 1- Temperature, 2 - Weight, 3- Height\n "); int i,j; double temp; scanf("%i", &i); printf("Enter the temperature:\n"); scanf("%le", &temp); double kel; kel = 273 + temp; switch (i) { case 1: printf("1 - Celsius to Kelvin, 2- Kelvin to Celsius\n" "3 - Celsius to Farehnheit, 4 - Farhenheit to celsius\n" "5-Kelvin to Farhenheit, 6 - Farhenheit to Kelvin\n"); scanf("%i\n", &j); switch (j) { case 7: printf("%f", temp + 273); break; case 8: printf("%f", temp - 273); default: break; } break; default: break; } return 0; }
Sandro
#include <stdio.h> #include <string.h> struct student { int id; char name[30]; float percentage; }; int main() { int i; struct student record1 = {1, "Raju", 90.5}; struct student record2, *record3 = NULL, *ptr1, record4; printf("Records of STUDENT1 - record1 structure \n"); printf(" Id : %d \n Name : %s\n Percentage : %f\n", record1.id, record1.name, record1.percentage); // 1st method to copy whole structure to another structure record2=record1; printf("\nRecords of STUDENT1 - Direct copy from \n record1 \n"); printf(" Id : %d \n Name : %s\n Percentage : %f\n", record2.id, record2.name, record2.percentage); // 2nd method to copy using memcpy function ptr1 = &record1; memcpy(record3, ptr1, sizeof(record1)); printf("\nRecords of STUDENT1 - copied from record1 " \ "using memcpy \n"); printf(" Id : %d \n Name : %s\n Percentage : %f\n", record3->id, record3->name, record3->percentage); // 3rd method to copy by individual members printf("\nRecords of STUDENT1 - Copied individual " \ "members from record1 \n"); record4.id=record1.id; strcpy(record4.name, record1.name); record4.percentage = record1.percentage; printf(" Id : %d \n Name : %s\n Percentage : %f\n", record4.id, record4.name, record4.percentage); return 0; }
for record3 you have to reserve memory before copying the data, than when you finish to use record3 don't forget to release the memory....
danya
Hi guys, someone can help to read RBG BMP file in C please?
danya
i have no idea how to do it
Sandro
Hi guys, someone can help to read RBG BMP file in C please?
it's an school assignment or for what?
Sandro
i have no idea how to do it
read this first: https://en.wikipedia.org/wiki/BMP_file_format
danya
struct pixel* read_data(FILE* stream, const struct bmp_header* header){ if(stream == NULL || header == NULL){ return 0; } // w == 1 && p == 1; w == 2 && p == 2; w == 3 && p == 3; w == 4 && p == 0 int padding = header->width % 4; int num_of_pixels = header->width * header->height; struct pixel* Pixel[num_of_pixels]; fseek(stream, 54, SEEK_SET); //move 54B (header size) int index_p = 0; for(int i = 0; i < header->height; i++){ for(int j = 0; j < header->width; j++){ Pixel[index_p] = malloc(sizeof(struct pixel)); fread(&(Pixel[index_p]->blue), 1, 1, stream); fread(&(Pixel[index_p]->green), 1, 1, stream); fread(&(Pixel[index_p]->red), 1, 1, stream); index_p++; } fseek(stream, padding, SEEK_CUR); //padding at the end of row } return *Pixel; } But its not working
danya
I have this,but not correct:(
B220059_Subhra_Bhanja
this code it's totally confusing.....what this program should do! just explain what you the user have to input, what the program should do, and what it should be the output?
Hey! Thanks for your time. I just fixed the code. It was something silly. I put \n in the scanf function. So now that i removed it works
Anonymous
I hate that C++ templates are powerful af
Anonymous
Makes porting to different language very difficult
hades
How to us z shadow
paper
Will it make the program faster if you would first check whenever a number is even (n%2 == 0) and then check if the number is devisible by some other even number (n%ev == 0) or just check if the number is devisible by 'ev' Which will have faster result?
Tushar
Remainder is not 0
paper
Remainder is not 0
This statement is inside an if
Anonymous
Where is the admin ?
Danila White
Hi guys, maybe you know how to reduce this free (annoying) space in Visual Studio 2022? Screenshot: https://ibb.co/8j2bpX2
Roxifλsz 🇱🇹
@K11M1
He's at a lecture
Anonymous
He's at a lecture
Ok bro thanks for deleting
klimi
ah i see, thank you collegue Roxifas
Gilded
https://batbin.me/scarebabe how to execute this code its working fine only
Gilded
this wont work in all compilers
Ольга
Good day. I have some questions. Someone knows how to sort the matrix by the last row? so that not only the elements of the last row are sorted but also other elements above it. I am very grateful for any future help
Gilded
#include<stdio.h> struct book { char book_name[100]; char first_author_name[100]; int book_id; int pages; char book_type[100]; char book_category[100]; }; void display(int a,char s[100],char t[100],char r[100]) { printf("%d ",a); printf("%s ",s); printf("%s ",t); printf("%s ",r); } int main() { int n; scanf("%d ",&n); struct book ob[n]; for(int i=0;i<n;i++) { scanf("%d ",&ob[i].book_id); scanf("%s ",&ob[i].book_type); scanf("%s ",&ob[i].book_name); ob[i].book_category=ob[i].book_id+ob[i].book_type+ob[i].book_name; display(ob[i].book_id,ob[i].book_type,ob[i].book_name,ob[i].book_category); } return 0; }
klimi
what are mistakes in this please say
Scanf %s is not recommended I think
Alviro Iskandar
Yeah, don't use scanf with %s specifier, it is vulnerable to buffer overflow
Alviro Iskandar
If your buffer is 100 bytes, then your scanf specifier should limit the input at 99 characters (leaving 1 byte for the NUL char), so use %99s for 100 bytes char buffer
Alviro Iskandar
ob[i].book_category=ob[i].book_id+ob[i].book_type+ob[i].book_name; Invalid operands to binary expression ('char *' and 'char [100]')
your arrays decay to pointer, so those should be: scanf("%99s", ob[i].book_type); scanf("%99s", ob[i].book_name);
Alviro Iskandar
omit the & for array of chars to scanf
Gilded
omit the & for array of chars to scanf
after doing this, that's different error for different line
Alviro Iskandar
after doing this, that's different error for different line
what do you want to do on this line? ob[i].book_category = ob[i].book_id+ob[i].book_type+ob[i].book_name;
Alviro Iskandar
are you going to concatenate all of them to string? those are int and array of chars, using + operator doesn't make any sense
Alviro Iskandar
this is question
yeah, i know, use snprintf for that
Alviro Iskandar
also scanf may fail, you should always check its return value and abort when fails, otherwise it will be undefined behavior since it is leaving the variable uninitialized when fails
Gilded
#include <stdio.h> #include <string.h> struct Book_Data { char book_name[50]; char first_author_name[50]; int book_id; int pages; char book_type[10]; }; void category(int n,char m[50],char o[10],char p[10]); int main(){ int n,i; printf("Enter the value of n: "); scanf("%d",&n); struct Book_Data book[n]; for (i = 0; i <n; i++) { printf("\nEnter the book name: "); scanf("%s",book[i].book_name); printf("\nEnter the author name: "); scanf("%s",book[i].first_author_name); printf("\nEnter the book id: "); scanf("%d",&book[i].book_id); printf("\nEnter the number of pages: "); scanf("%d",&book[i].pages); printf("\nEnter the book type: "); scanf("%s",book[i].book_type); } for (i = 0; i <n; i++) { printf("\nBook name is %s",book[i].book_name); printf("\nBook id is %d",book[i].book_id); printf("\nAuthor is %s",book[i].first_author_name); printf("\nPages are %d",book[i].pages); printf("\nBook type is %s",book[i].book_type); } for (i = 0; i < n; i++) { category(book[i].book_id,book[i].book_name,book[i].first_author_name,book[i].book_type); } } void category(int n,char m[50],char o[10],char p[10]) { int len,i; char p1[10]; strcpy(p1,p); printf("\nCategory is %d",n); len=strlen(p1); for (i = 0; i < len; i++) { if (p1[i]=='f') { printf("fi"); } if (p1[i]=='e') { printf("en"); } if (p1[i]=='s') { printf("sc"); } if (p1[i]=='j') { printf("jo"); } if (len<2) { printf("XX"); } for (i = 0; i < 2; i++) { printf("%c",m[i]); } } }
Gilded
#include <stdio.h> #include <string.h> struct Book_Data { char book_name[50]; char first_author_name[50]; int book_id; int pages; char book_type[10]; }; void category(int n,char m[50],char o[10],char p[10]); int main(){ int n,i; printf("Enter the value of n: "); scanf("%d",&n); struct Book_Data book[n]; for (i = 0; i <n; i++) { printf("\nEnter the book name: "); scanf("%s",book[i].book_name); printf("\nEnter the author name: "); scanf("%s",book[i].first_author_name); printf("\nEnter the book id: "); scanf("%d",&book[i].book_id); printf("\nEnter the number of pages: "); scanf("%d",&book[i].pages); printf("\nEnter the book type: "); scanf("%s",book[i].book_type); } for (i = 0; i <n; i++) { printf("\nBook name is %s",book[i].book_name); printf("\nBook id is %d",book[i].book_id); printf("\nAuthor is %s",book[i].first_author_name); printf("\nPages are %d",book[i].pages); printf("\nBook type is %s",book[i].book_type); } for (i = 0; i < n; i++) { category(book[i].book_id,book[i].book_name,book[i].first_author_name,book[i].book_type); } } void category(int n,char m[50],char o[10],char p[10]) { int len,i; char p1[10]; strcpy(p1,p); printf("\nCategory is %d",n); len=strlen(p1); for (i = 0; i < len; i++) { if (p1[i]=='f') { printf("fi"); } if (p1[i]=='e') { printf("en"); } if (p1[i]=='s') { printf("sc"); } if (p1[i]=='j') { printf("jo"); } if (len<2) { printf("XX"); } for (i = 0; i < 2; i++) { printf("%c",m[i]); } } }
len=strlen(p1); Implicit conversion loses integer precision: 'unsigned long' to 'int'
Sassan
/get
Sassan
/get ide
bunny
/notes
Anonymous
I am a fresher to study a c program . So pls help me and send notes from basics..
Alviro Iskandar
len=strlen(p1); Implicit conversion loses integer precision: 'unsigned long' to 'int'
strlen() returns a size_t, which is unsigned long in your case, so instead of using int, you should use size_t to declare the i
\Device\NUL
#include <stdio.h> #include <string.h> struct Book_Data { char book_name[50]; char first_author_name[50]; int book_id; int pages; char book_type[10]; }; void category(int n,char m[50],char o[10],char p[10]); int main(){ int n,i; printf("Enter the value of n: "); scanf("%d",&n); struct Book_Data book[n]; for (i = 0; i <n; i++) { printf("\nEnter the book name: "); scanf("%s",book[i].book_name); printf("\nEnter the author name: "); scanf("%s",book[i].first_author_name); printf("\nEnter the book id: "); scanf("%d",&book[i].book_id); printf("\nEnter the number of pages: "); scanf("%d",&book[i].pages); printf("\nEnter the book type: "); scanf("%s",book[i].book_type); } for (i = 0; i <n; i++) { printf("\nBook name is %s",book[i].book_name); printf("\nBook id is %d",book[i].book_id); printf("\nAuthor is %s",book[i].first_author_name); printf("\nPages are %d",book[i].pages); printf("\nBook type is %s",book[i].book_type); } for (i = 0; i < n; i++) { category(book[i].book_id,book[i].book_name,book[i].first_author_name,book[i].book_type); } } void category(int n,char m[50],char o[10],char p[10]) { int len,i; char p1[10]; strcpy(p1,p); printf("\nCategory is %d",n); len=strlen(p1); for (i = 0; i < len; i++) { if (p1[i]=='f') { printf("fi"); } if (p1[i]=='e') { printf("en"); } if (p1[i]=='s') { printf("sc"); } if (p1[i]=='j') { printf("jo"); } if (len<2) { printf("XX"); } for (i = 0; i < 2; i++) { printf("%c",m[i]); } } }
My suggestion u should use switch case for better readability and using putchar for printing char
Alviro Iskandar
#include <stdio.h> #include <string.h> struct Book_Data { char book_name[50]; char first_author_name[50]; int book_id; int pages; char book_type[10]; }; void category(int n,char m[50],char o[10],char p[10]); int main(){ int n,i; printf("Enter the value of n: "); scanf("%d",&n); struct Book_Data book[n]; for (i = 0; i <n; i++) { printf("\nEnter the book name: "); scanf("%s",book[i].book_name); printf("\nEnter the author name: "); scanf("%s",book[i].first_author_name); printf("\nEnter the book id: "); scanf("%d",&book[i].book_id); printf("\nEnter the number of pages: "); scanf("%d",&book[i].pages); printf("\nEnter the book type: "); scanf("%s",book[i].book_type); } for (i = 0; i <n; i++) { printf("\nBook name is %s",book[i].book_name); printf("\nBook id is %d",book[i].book_id); printf("\nAuthor is %s",book[i].first_author_name); printf("\nPages are %d",book[i].pages); printf("\nBook type is %s",book[i].book_type); } for (i = 0; i < n; i++) { category(book[i].book_id,book[i].book_name,book[i].first_author_name,book[i].book_type); } } void category(int n,char m[50],char o[10],char p[10]) { int len,i; char p1[10]; strcpy(p1,p); printf("\nCategory is %d",n); len=strlen(p1); for (i = 0; i < len; i++) { if (p1[i]=='f') { printf("fi"); } if (p1[i]=='e') { printf("en"); } if (p1[i]=='s') { printf("sc"); } if (p1[i]=='j') { printf("jo"); } if (len<2) { printf("XX"); } for (i = 0; i < 2; i++) { printf("%c",m[i]); } } }
This is still vulnerable to buffer overflow and you haven't addressed the previous reviews. 1. Don't use scanf with %s specifier, it is vulnerable to buffer overflow. 2. scanf may fail, you should always check its return value, now, when it fails, you will be accessing uninitialized variables, it is UB. 3. Don't use VLA to declare the array book here, it's vulnerable to stack overflow.
Alviro Iskandar
If you ask for code review again, please address those first!
ASH ‏̶‎̵‏̸‎̷‏̵‎̴‏̷‎̴‏̴‎̴‏̷‎̸‏̴‎̵‏̵‎̵‏̶‎̵‏̸‎̷‏̵‎̴‏̷‎̴‏̴‎̴‏̷‎̸‏̴‏̵
Has anyone ever worked with the td library?
Gilded
strlen() returns a size_t, which is unsigned long in your case, so instead of using int, you should use size_t to declare the i
thanks i fixed it like this #include <stdio.h> #include <string.h> struct Book_Data { char book_name[50]; char first_author_name[50]; int book_id; int pages; char book_type[10]; }; void category(int n,char m[50],char o[10],char p[10]); int main(){ int n,i; printf("Enter the value of n: "); scanf("%d",&n); struct Book_Data book[n]; for (i = 0; i <n; i++) { printf("\nEnter the book name: "); scanf("%s",book[i].book_name); printf("\nEnter the author name: "); scanf("%s",book[i].first_author_name); printf("\nEnter the book id: "); scanf("%d",&book[i].book_id); printf("\nEnter the number of pages: "); scanf("%d",&book[i].pages); printf("\nEnter the book type: "); scanf("%s",book[i].book_type); } for (i = 0; i <n; i++) { printf("\nBook name is %s",book[i].book_name); printf("\nBook id is %d",book[i].book_id); printf("\nAuthor is %s",book[i].first_author_name); printf("\nPages are %d",book[i].pages); printf("\nBook type is %s",book[i].book_type); } for (i = 0; i < n; i++) { category(book[i].book_id,book[i].book_name,book[i].first_author_name,book[i].book_type); } } void category(int n,char m[50],char o[10],char p[10]) { size_t len,i; char p1[10]; strcpy(p1,p); printf("\nCategory is %d",n); len=strlen(p1); for (i = 0; i < len; i++) { if (p1[i]=='f') { printf("fi"); } if (p1[i]=='e') { printf("en"); } if (p1[i]=='s') { printf("sc"); } if (p1[i]=='j') { printf("jo"); } if (len<2) { printf("XX"); } for (i = 0; i < 2; i++) { printf("%c",m[i]); } } }
Gilded
thanks i fixed it like this #include <stdio.h> #include <string.h> struct Book_Data { char book_name[50]; char first_author_name[50]; int book_id; int pages; char book_type[10]; }; void category(int n,char m[50],char o[10],char p[10]); int main(){ int n,i; printf("Enter the value of n: "); scanf("%d",&n); struct Book_Data book[n]; for (i = 0; i <n; i++) { printf("\nEnter the book name: "); scanf("%s",book[i].book_name); printf("\nEnter the author name: "); scanf("%s",book[i].first_author_name); printf("\nEnter the book id: "); scanf("%d",&book[i].book_id); printf("\nEnter the number of pages: "); scanf("%d",&book[i].pages); printf("\nEnter the book type: "); scanf("%s",book[i].book_type); } for (i = 0; i <n; i++) { printf("\nBook name is %s",book[i].book_name); printf("\nBook id is %d",book[i].book_id); printf("\nAuthor is %s",book[i].first_author_name); printf("\nPages are %d",book[i].pages); printf("\nBook type is %s",book[i].book_type); } for (i = 0; i < n; i++) { category(book[i].book_id,book[i].book_name,book[i].first_author_name,book[i].book_type); } } void category(int n,char m[50],char o[10],char p[10]) { size_t len,i; char p1[10]; strcpy(p1,p); printf("\nCategory is %d",n); len=strlen(p1); for (i = 0; i < len; i++) { if (p1[i]=='f') { printf("fi"); } if (p1[i]=='e') { printf("en"); } if (p1[i]=='s') { printf("sc"); } if (p1[i]=='j') { printf("jo"); } if (len<2) { printf("XX"); } for (i = 0; i < 2; i++) { printf("%c",m[i]); } } }
but i got this issue https://telegra.ph/file/c1d6bda0c5cef0927b2ac.jpg
Gilded
not got same output as there
Gilded
thanks i fixed it like this #include <stdio.h> #include <string.h> struct Book_Data { char book_name[50]; char first_author_name[50]; int book_id; int pages; char book_type[10]; }; void category(int n,char m[50],char o[10],char p[10]); int main(){ int n,i; printf("Enter the value of n: "); scanf("%d",&n); struct Book_Data book[n]; for (i = 0; i <n; i++) { printf("\nEnter the book name: "); scanf("%s",book[i].book_name); printf("\nEnter the author name: "); scanf("%s",book[i].first_author_name); printf("\nEnter the book id: "); scanf("%d",&book[i].book_id); printf("\nEnter the number of pages: "); scanf("%d",&book[i].pages); printf("\nEnter the book type: "); scanf("%s",book[i].book_type); } for (i = 0; i <n; i++) { printf("\nBook name is %s",book[i].book_name); printf("\nBook id is %d",book[i].book_id); printf("\nAuthor is %s",book[i].first_author_name); printf("\nPages are %d",book[i].pages); printf("\nBook type is %s",book[i].book_type); } for (i = 0; i < n; i++) { category(book[i].book_id,book[i].book_name,book[i].first_author_name,book[i].book_type); } } void category(int n,char m[50],char o[10],char p[10]) { size_t len,i; char p1[10]; strcpy(p1,p); printf("\nCategory is %d",n); len=strlen(p1); for (i = 0; i < len; i++) { if (p1[i]=='f') { printf("fi"); } if (p1[i]=='e') { printf("en"); } if (p1[i]=='s') { printf("sc"); } if (p1[i]=='j') { printf("jo"); } if (len<2) { printf("XX"); } for (i = 0; i < 2; i++) { printf("%c",m[i]); } } }
this code has some timeout issue how to fix?
Gilded
this code has some timeout issue how to fix?
this is issue https://telegra.ph/file/280820d307730d8ecd133.jpg
labyrinth
no instance of overloaded function "std::__cxx11::list<_Tp, _Alloc>::push_back [with _Tp=IChunk *, _Alloc=std::allocator<IChunk *>]" matches the argument list -- argument types are: (IChunk *) -- object type is: std::__cxx11::list<IChunk *, std::allocator<IChunk *>>
labyrinth
i dont understand why it does not work
Anonymous
Write a program that finds all integers less than 200 that are exactly divisible by the number obtained by the sum of their digits and print the numbers to the screen. For example, 20 meets the condition since 2+0=2 and 20 is exactly divisible by 2.
Anonymous
Anyone who can help with it?
Anonymous
https://discourse.llvm.org/t/rfc-lifetime-annotations-for-c/61377 Finally attempts at bringing to the C++ table the advantages that Rust offers.
Msd
In compiler it showing error size is not declared in scope
Msd
#include <iostream> using namespace std; int main(){ char dummy [] {"Hi this is sadeesh kumar"}; cout << dummy << endl; size_t acc{}; for (size_t i{0}; i < size(dummy); ++i){ } return 0; }
Msd
And what's size?)
To get the size of array bro
Anonymous
To get the size of array bro
There are no size keyword in C nor C++
Msd
There are no size keyword in C nor C++
Brother in YouTube search c++ in 31 hrs In that video 13:01:00 check that time stamp you will see this one and he got output I can't share pics here
Anonymous
For containers yea, but dummy is not a container