קורס אמבדד – 004 – RB18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include <stdio.h> #include <string.h> // create struct with person1 variable struct Person { char name[50]; int citNo; float salary; } person1; int main() { // assign value to name of person1 strcpy(person1.name, "George Orwell"); // assign values to other person1 variables person1.citNo = 1984; person1. salary = 2500; // print struct variables printf("Name: %s\n", person1.name); printf("Citizenship No.: %d\n", person1.citNo); printf("Salary: %.2f", person1.salary); return 0; } |
1 2 3 |
strcpy(person1.name, "George Orwell"); person1.citNo = 1984; person1. salary = 2500; |
https://www.programiz.com/c-programming/c-structures
קבצים
https://www.geeksforgeeks.org/c-fopen-function-with-examples/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <stdio.h> #include <stdlib.h> int main() { char sentence[1000]; // creating file pointer to work with files FILE *fptr; // opening file in writing mode fptr = fopen("program.txt", "w"); // exiting program if (fptr == NULL) { printf("Error!"); exit(1); } printf("Enter a sentence:\n"); fgets(sentence, sizeof(sentence), stdin); fprintf(fptr, "%s", sentence); fclose(fptr); return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include <stdio.h> #include <stdlib.h> int main() { int num; FILE *fptr; // use appropriate location if you are using MacOS or Linux fptr = fopen("C:\\program.txt","w"); if(fptr == NULL) { printf("Error!"); exit(1); } printf("Enter num: "); scanf("%d",&num); fprintf(fptr,"%d",num); fclose(fptr); return 0; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <stdio.h> #include <stdlib.h> int main() { int num; FILE *fptr; if ((fptr = fopen("C:\\program.txt","r")) == NULL){ printf("Error! opening file"); // Program exits if the file pointer returns NULL. exit(1); } fscanf(fptr,"%d", &num); printf("Value of n=%d", num); fclose(fptr); return 0; } |
STM32
https://smartsolutions4home.com/how-to-program-stm32/
28-BYJ4
NEMA17