C언어 관련된 %*c 질문...

georgekyung의 이미지

간단한 프로그램 만드는 연습을 하고있는데요...
===============================================
.
.
.
printf("\n점수, 시수:");
scanf("%*c%c %d",&grade,&num); //점수 학점 입력


switch(grade) //switch ~ case 문을 통해 각 학점별로 계산 하고 저장!
{
case'A':
case'a':
rsl+=4*num; //계속 값이 누적되는 식으로... (다른 학점의 경우도 똑같이...)
numrsl+=num;
n--;
break;
~
.
.
.
================================================================

이런식으로 짜봤는데요

첨에 학점,시수 입력하는 부분에서 %c와 %d로 써놓고 해보니 계속 이상하게
잘못된 부분이 없는데,,, case를 지나치더라구요 - -;;

그래서 물어보니 %*C를 입력하면된다고해서...해봤는데

%*c가..무슨기능을 하는거죠? 물어봐도 이해가 안가서요 ㅠㅠ

좀 알려주세요 !!ㅠㅠ(너무 어렵네요)

C언어 관련되서 참고할 사이트 뭐 괜찮은곳 없나요?

clique의 이미지

%c 로 문자를 인식하지만, 변수에 저장하지는 않습니다.

select99의 이미지

할당금지라고...

입력된놈을 버리는것이죠..

winapi.co.kr
보시면 잘나와있어요..

georgekyung의 이미지

./

Geor

shint의 이미지

------------------------------------------------------
네이버에서 scanf %*c 로 검색 결과.

c 에서 scanf("%*c%c", &cont);중에서 *는 무슨 뜻인가요?
http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=66674260&qb=c2NhbmYgJSpj&enc=utf8&section=kin&rank=2&search_sort=0&spq=0

%*c 에서 *는 이위치에 있는 문자는 무시하라는 것을 의미합니다. 라고 합니다.

------------------------------------------------------
C 문법은 요기를 참고하세요.
http://www.cplusplus.com/reference/cstdio/scanf/

%[*][width][length]specifier

* An optional starting asterisk indicates that the data is to be read from the stream but ignored (i.e. it is not stored in the location pointed by an argument).

------------------------------------------------------
영어를 모르면 구글번역을 참고 해보세요.
http://translate.google.com/?hl=en&tab=wT

------------------------------------------------------
테스트 코드 입니다.

#include <cstdlib>
#include <iostream>
 
using namespace std;
 
int main(int argc, char *argv[])
{
 
char grade = 0;
int num1 = 0;
int num2 = 0;
int rsl = 0;
int numrsl = 0;
int n = 0;
 
printf("\n점수, 시수:");
 
 
//%데이터가 입력되기 위한 형식 ****갯수만큼 공간무시 넓이 길이 c문자. d숫자.
//%[*][width][length]specifier
 
 
//점수, 시수:++++20
//+ 43 20 0
//scanf("%*3c%c%d", &grade, &num1);
 
//점수, 시수:++++20
//+ 43 20 0
scanf("%***c%c%d", &grade, &num1);
 
//1.입력 방법 : 10 + 20 또는 10 +20
//scanf("%d%*c%c%d", &num1, &grade, &num2);
 
//2. 1과 같음. 10+20
//scanf("%d%c%d", &num1, &grade, &num2);
 
//2. 1과 같음 
//scanf("%d",&num1); //학점 입력
//scanf("%*c%c",&grade); //점수
//scanf("%d",&num2); //학점 입력
 
//3. 1과 2와 다름 
//scanf("%d %*c%c %d", &num1, &grade, &num2); //점수 학점 입력
 
//출력 결과 : + 43 10 20 
printf("%c %d %d %d\n", grade, grade, num1, num2);
 
switch(grade) //switch ~ case 문을 통해 각 학점별로 계산 하고 저장!
{
case'A':
case'a':
rsl+=4*num1; //계속 값이 누적되는 식으로... (다른 학점의 경우도 똑같이...)
numrsl+=num1;
n--;
//점수, 시수:10 a 20
//a 97 10 20
//10 40 10
printf("%d %d %d\n", num1, rsl, numrsl);
break;
}
 
    system("PAUSE");
    return EXIT_SUCCESS;
}

------------------------------------------------------
참고로 switch() 관련 내용도 있습니다.
http://kldp.org/node/3615

----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.

매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.

각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.