0% found this document useful (0 votes)
44 views5 pages

Document

The document defines functions to print formatted tables and lines, including centered text. It defines a struct to store student data with name, year of birth, and sex fields. The main function gets student data, prints the table header, and calls the showAll function to display the student records in a formatted table. It implements a simple program to input and display a list of student records.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views5 pages

Document

The document defines functions to print formatted tables and lines, including centered text. It defines a struct to store student data with name, year of birth, and sex fields. The main function gets student data, prints the table header, and calls the showAll function to display the student records in a formatted table. It implements a simple program to input and display a list of student records.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include <stdio.

h>
#include <string.h>

struct hs;
char* lines(char c, int len);
char* center(char s[],int len);
void printLine(char c);
void printTitle();
void showAll();
void saveToFile();
int main()
{
int n = 1;
struct hs {}list[100];
for(int i=0;i<n;i++){
printf("Ho va Ten: ");
gets(list[i].name);
printf("Nam sinh: ");
scanf("%d%*c",&list[i].yob);
printf("Gioi tinh: ");
scanf("%d%*c",&list[i].sex);
}
printTitle();
showAll(list,n);

return 0;
}
struct hs{
char name[100];
int yob;
int sex;
};

char* lines(char c, int len){


static char s[1000];
for(int i = 0; i < len; i++)
s[i] = c;
s[len] = '\0';
return s;
}

char* center(char s[],int len){


int llen = len - strlen(s);
llen /= 2;
static char s_new[1000] = "";
for(int i = 0; i < llen; i++)
s_new[i] = 32;
for(int i = 0; i < strlen(s); i++)
s_new[llen+i] = s[i];
for(int i = llen + strlen(s); i < len; i++)
s_new[i] = 32;
s_new[len] = '\0';
return s_new;
}
void printLine(char c){
printf("+%s", lines(c, 52));
printf("+%s+", lines(c, 10));
printf("%s+", lines(c, 12));
}
void printTitle(){
char colunms[][10] = {"Ho va Ten","Nam sinh","Gioi tinh"};

printLine('=');

printf("\n| %s ",center(colunms[0], 50));


printf("| %s |", center(colunms[1], 8));
printf(" %s |\n",center(colunms[2], 10));
printLine('=');
}

void showAll(struct hs list[], int size){


char sex[][5] = {"---", "Nu", "Nam"};
for(int i = 0; i < size; i++){
printf("\n| %s", list[i].name, 50);
printf("| %4d%5s", list[i].yob, " ");
if(list[i].sex >= 0 && list[i].sex <3){
printf("| %s |\n", center(sex[list[i].sex], 10));
}
printLine('-');
}
}
void saveToFile(struct hs list[], int size){
FILE *f;
f = fopen("C:\\Users\\MAY 1\\Documents\\DevC","w");
if(f == NULL){
printf("Khong tao duoc file");
return;
}
for(int i=0; i<size; i++){
fwrite(&list[i],sizeof(struct hs), 1, f);
if(fwrite == 0){
printf("Luu khong thanh cong");
return;
}
}
fclose(f);
}

000000000000000000
/******************************************************************************

Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>
#include <string.h>

struct hs{
char name[100];
int yob;
int sex;
};
char* lines(char c, int len){
static char s[1000];
for(int i = 0; i < len; i++)
s[i] = c;
s[len] = '\0';
return s;
}
char* center(char s[],int len){
int llen = len - strlen(s);
llen /= 2;
static char s_new[1000] = "";
for(int i = 0; i < llen; i++)
s_new[i] = 32;
for(int i = 0; i < strlen(s); i++)
s_new[llen+i] = s[i];
for(int i = llen + strlen(s); i < len; i++)
s_new[i] = 32;
s_new[len] = '\0';
return s_new;
}
void printLine(char c){
printf("+%s", lines(c, 52));
printf("+%s+", lines(c, 10));
printf("%s+", lines(c, 12));
}
void printTitle(){
char colunms[][10] = {"Ho va Ten","Nam sinh","Gioi tinh"};

printLine('=');

printf("\n| %s ",center(colunms[0], 50));


printf("| %s |", center(colunms[1], 8));
printf(" %s |\n",center(colunms[2], 10));
printLine('=');
}
void showAll(struct hs list[], int size){
char sex[][5] = {"---", "Nữ", "Nam"};
for(int i = 0; i < size; i++){
printf("\n| %s", list[i].name, 50);
printf("| %04d%05s", list[i].yob, " ");
if(list[i].sex >= 0 && list[i].sex <3){
printf("| %s |\n", center(sex[list[i].sex], 10));
}
printLine('-');
}
}
int main()
{
int n = 1;
struct hs list[100];
for(int i=0;i<n;i++){
printf("Ho va Ten: ");
gets(list[i].name);
printf("Nam sinh: ");
scanf("%d%*c",&list[i].yob);
printf("Gioi tinh: ");
scanf("%d%*c",&list[i].sex);
}
printTitle();
showAll(list,n);

return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy