728x90

๋ฌธ์ œ ์„ค๋ช…

๊ณต๋ฐฑ ๋ฌธ์ž๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ๋Š” ๋ฌธ์žฅ์„ ์ž…๋ ฅ๋ฐ›๊ณ  ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๋Š” ์—ฐ์Šต์„ ํ•ด๋ณด์ž.

์˜ˆ์‹œ
char data[2001];
fgets(data, 2000, stdin);
printf("%s", data);

์œ„์™€ ๊ฐ™์ด ์‹คํ–‰ํ•˜๋ฉด ๊ณต๋ฐฑ์ด ํฌํ•จ๋œ ๋ฌธ์žฅ์„ ํ‚ค๋ณด๋“œ(stdin)๋กœ ์ž…๋ ฅ๋ฐ›์•„
์ตœ๋Œ€ 2000์ž๊นŒ์ง€ data[ ] ๊ณต๊ฐ„์— ์ €์žฅํ•˜๊ณ  ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ๋‹ค.

%s ๋Š” ๋ฌธ์ž์—ด(string, ์‹ค๋กœ ์—ฐ๊ฒฐ๋œ ๋ฌธ์ž๋“ค. ๋ฌธ์žฅ)๋กœ ์ถœ๋ ฅํ•˜๋ผ๋Š” ์˜๋ฏธ์ด๋‹ค.

์ฐธ๊ณ 
fgets( ) ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ณต๋ฐฑ๋ฌธ์ž๊ฐ€ ํฌํ•จ๋˜์–ด์ž‡๋Š” ๋ฌธ์žฅ์„ ์ž…๋ ฅ๋ฐ›์•„ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋‹ค.
๋งŒ์•ฝ, ์•„๋ž˜์ฒ˜๋Ÿผ
scanf("%s", ... ) ๋ฅผ ์ด์šฉํ•ด ๋ฌธ์žฅ์„ ์ž…๋ ฅ๋ฐ›์œผ๋ฉด, ์ฒซ ๋ฒˆ์งธ ๋‹จ์–ด๊นŒ์ง€๋งŒ ์ €์žฅ๋œ๋‹ค.

char data[51] = ""; //์ตœ๋Œ€ 50๋ฌธ์ž๊นŒ์ง€ ์ €์žฅ ๊ฐ€๋Šฅ
scanf("%s", data);


์ž…๋ ฅ

๊ณต๋ฐฑ์ด ํฌํ•จ๋˜์–ด ์žˆ๋Š” ํ•œ ๋ฌธ์žฅ์ด ์ž…๋ ฅ๋œ๋‹ค.
๋‹จ, ์ž…๋ ฅ๋˜๋Š” ๋ฌธ์žฅ์€ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋‹จ์–ด๋กœ ๊ตฌ์„ฑ๋˜๊ณ , ์—”ํ„ฐ๋กœ ๋๋‚˜๋ฉฐ,
์ตœ๋Œ€ ๊ธธ์ด๋Š” 2000 ๋ฌธ์ž๋ฅผ ๋„˜์ง€ ์•Š๋Š”๋‹ค.

 

์ถœ๋ ฅ

์ž…๋ ฅ๋œ ๋ฌธ์žฅ์„ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•œ๋‹ค.

 

์ž…๋ ฅ์˜ˆ์‹œ
Programming is very fun!!

์ถœ๋ ฅ์˜ˆ์‹œ
Programming is very fun!!

๋ฌธ์ œ ํ’€์ด

#include <stdio.h>

int main(){
    char data[2001];
    fgets(data,2000,stdin);
    printf("%s",data);
    
    return 0;
}

+ Recent posts