+ 4

Convert code to C language

#include<stdio.h> struct Course { int user; int video; int level; void ShowInfo() { printf("Number of users:"); printf("user\n"); printf( "Number of video:"); printf("video\n"); printf("Numbre of course:"); printf("Numbre\n"); } }; int main() { Course py; py.user= 3192; py.video = 15; py.level =3; py.ShowInfo(); return 0; One can change this code to C language,,, I do not know what my problems are 🥺🙏

18th Feb 2022, 12:59 PM
Mhdis
Mhdis - avatar
6 Respostas
+ 4
#include<stdio.h> typedef struct Course { int user; int video; int level; } Course; void ShowInfo(Course c) { printf("Number of users:"); printf("%d\n", c.user); printf( "Number of video:"); printf("%d\n", c.video); printf("Numbre of course:"); printf("%d\n", c.level); } int main() { Course py; py.user= 3192; py.video = 15; py.level =3; ShowInfo(py); return 0; }
18th Feb 2022, 1:38 PM
Мартин 😑🎵
Мартин 😑🎵 - avatar
+ 3
C structs are plain data carrier, I think you can turn that ShowInfo() into a regular function, allow it to accept a parameter of struct `Course` type, which will be used as source of data to print.
18th Feb 2022, 1:18 PM
Ipang
+ 2
So how do I change the code?
18th Feb 2022, 1:32 PM
Mhdis
Mhdis - avatar
+ 2
Tnxxxx🙏🙏
18th Feb 2022, 1:56 PM
Mhdis
Mhdis - avatar
+ 1
In C a struct can't have functions in it
18th Feb 2022, 1:18 PM
Мартин 😑🎵
Мартин 😑🎵 - avatar
0
He would be welcome xxx
20th Feb 2022, 4:03 PM
IDK
IDK - avatar