본문 바로가기
반응형

C basic10

1. Quiz[C Basic] 다음 프로그램을 실행할 경우 출력 결과를 작성하라.(오류가 나면 오류도 함께 작성할 것.) 1.1. #include #define PR(X,Y,Z) printf("X=%d, Y=%d, Z=%d\n", X, Y, Z) int x=1, y=3, z=7; int sum(int *x, int y){ PR(z,*x,y); *x = 4; y = -y; return (*x+y+z); } int main(){ int x=2, z; z=sum(&y, x); PR(x,y,z); z=sum(&x, z); PR(y,z,x); return 0; } 1.2. #include int x = 10; void f( ){ x++; printf("%d, ", x); } void g( ){ static int x = 30; printf(".. 2021. 11. 7.
10. File[C Basic] * fgets exapmle #include int main() { char line[255]; FILE *file=fopen("example_fputs.txt","r"); if(file==NULL){ printf("파일열기 실패\n"); return 1; } while((fgets(line,sizeof(line),file))!=NULL) printf("%s",line); fclose(file); return 0; } * fprintf exapmle #include int main() { int num1=20; int num2=40; FILE *file=fopen("example_fprintf.txt","w"); if(file==NULL){ printf("파일열기 실패\n"); return 1; } fp.. 2021. 11. 7.
9. Struct[C Basic] * 2 char text[MAX][80]; char *temp = NULL; gets(&text[i][0]); for (i = 0;i < MAX;i++) { strcpy(std[i].name, strtok(&strtok(&text[i][], "/"))); atoi()이용하여 stdnum에 저장 } scanf("%s / %d", &korea_university[i].name, &korea_university[i].stdnum); scanf("%s \ %d",,); while (scanf("%c", &korea_university[i].name[j++] != '/')); void bubble(struct *std) { } temp_int = korea_university[j].stdnum; korea_uni.. 2021. 11. 7.
8. Bit operator[C Basic] *1 int func(unsigned int bits){ unsigned int i; unsigned int mask=1 2021. 11. 7.
7. String[C Basic] * example #include #include int checkcase(char cha); void convertCharCase(char *sPtr); int main(void) { char str[200] = "PoINteR is vERy ImPorTAnt in C pRoGraMMing, SO STudEnt nEEd tO pRACtiCe usING poINTer"; convertCharCase(str); } int checkcase(char cha) { if (65 2021. 11. 7.
6. Pointer[C Basic] 6.1. Write program using pointer The function should receive three integer pointer: 1. Increase 1st argument by 1 2. Multiply 2nd argument by 3rd argument 3. Assign the result to 2nd argument 4. Swap 2nd and 3rd argument #include cal(int *a, int *b, int *c) { (*a)++; (*b) *= (*c); int temp = *b; *b = *c; *c = temp; } int main() { int a, b, c; printf("Enter three numbers: "); scanf("%d %d %d", &a.. 2021. 11. 7.
반응형