그림과 같은 프로그램을 만드는데요...
노래 제목, 가수, 러닝타임, 음질의 데이터를 입력 받아 출력하는 프로그램을 만들어 보자.
공백이 있는 문자열을 입력 받을 때는 gets(char *) 함수를 이용해 보자!
버퍼를 지우고 싶을 때는 getchar() 함수를 이용!
다음 함수를 정의하고 사용하자.
add_song : 노래 1곡 추가
print_songs: 저장된 노래 전체 출력
#include <stdio.h>
#include <string.h>
typedef struct
{
char title[30];
char artist[20];
int time[2];
int quality[3];
}SONG;
void add_song(SONG *p);
void print_songs(SONG list[], int n);
int main()
{
SONG list[10];
char comm[10];
int n = 0;
while (1) {
printf(">> ");
scanf("%s", comm);
if (strcmp(comm, "quit") == 0)
break;
else if (strcmp(comm, "add") == 0) {
add_song(&list[n]);
n++;
}
else if (strcmp(comm, "print") == 0) {
print_songs(list, n);
}
}
return 0;
}
void add_song(SONG *p)
{
getchar();
printf("TITLE : ");
gets((*p).title);
printf("ARTIST : ");
gets(&(*p).artist);
printf("TIME : ");
scanf("%d", &(*p).time);
printf("QUALITY : ");
scanf("%d", &(*p).quality);
printf(" ");
}
void print_songs(SONG list[], int n)
{
int i;
for (i = 1; i <= n; i++); {
printf("No. %d ", i);
printf("TITLE : %s", list[i].title);
printf("ARTIST : %s", list[i].artist);
printf("TIME : %dmin %dsec", list[i].time[1], list[i].time[2]);
printf("QUALITY : %dkbps", &list[i].quality);
}
}
add 함수 구현이 힘드네요 ㅠㅠ
도와주시는 분 suerte16으로 카톡주시면 스벅 키프티콘드릴게요
어렵지않은거 도와줄순있는데 뭐가 잘안됨?
글고 내보고짜라면 저렇게안짜겟지만 대충훑어보니까 저거 저대로하면 add기능구현해도 print 제대로안될껄? 가령 퀼리티를 int [3]으로 받아서 192면 1 / 9 / 2 이렇게 따로저장해놓고 출력함수구현할때보면 각각의 song list에있는 요소들을 인덱스 i 로 하나씩 출력하는데 그런식으로하면 제대로안나오겠지
VS 디버깅 돌리면 뭐가 틀렸는지 찾기 쉬움
좋은 습관은 아니지만
카톡으로 잘알려드렸음 ㅎㅎ 초보과제에 흐린바다가 또 기프티콘을! ㄳㄳ