본문 바로가기

공부방

C언어 정복 1일차


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

void main()
{
 char namelist[100];
 char temp[20];
 char *pData;
 int i;
 pData=namelist;
 for(i=0;i<10;i++){
  printf("%d 이름: ", i+1);
  gets(temp);
  strcpy(pData,temp);
  pData+=10;
 }
 pData=namelist;
 for(i=0;i<10;i++){
  printf("%s \n", pData);
  pData+=10;
 }
}
*/

사용자 삽입 이미지


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

void main()
{
 char namelist[140];
 char temp[20];
 char *pData;
 int mode, pos, len, jum;
 memset(namelist,0,100);
 while(1){
  printf("[1]번호설정 [2]입력 [3]출력 [0]종료\n");
  gets(temp);
  sscanf(temp,"%d", &mode);
  if(mode==0)
   break;
  switch(mode){
   case 1:
    printf("번호 ");
    gets(temp);
    sscanf(temp,"%d",&mode);
    pos=mode*14;
    pData=namelist+pos;
    break;
   case 2:
    printf("점수 ");
    gets(temp);
    sscanf(temp, "%d", &jum);
    memcpy(pData, &jum, 4);
    printf("이름 ");
    gets(temp);
    len=strlen(temp);
    if(len>10){
     printf("문자열 값이 큽니다.\n");
     break;
    }
    strcpy(pData+4, temp);
    break;
   case 3:
    memcpy(&jum, pData, 4);
    printf("%d, %s \n", jum, pData+4);
    break;
   default:
    printf("잘못 되었습니다.  \n");
    break;
  }
 }
}