[C언어] C언어 질문좀 올리겠습니다 ;;;

whitelazy의 이미지

윽.. 학교에서 유닉스 프로그래밍 수업이 있는데 이거 과제 하다가 도저히 버그를 못잡아서 질문좀 올립니다 ;;;

아래 코드에서 표시 해놓은 부분에서(전부다 for문...;;) 에러가 나는데
이유를 도저히 모르겠습니다 ㅡ.ㅜ
이넘잡고 씨름하다가 결국 제출시간도 넘겨서 메일로 보내는 놨는데.. ㅎㅎ;; 과연 받아주실련지 ;;
서버 사용자 폭주해서 못내면 멜로 받아준다곤 했었는데 어쩔지 모르겠네요 ;;;

어쨌던 코드랑 에러내용입니다 ;;
105번 라인 에러는 99번라인 에러때문에 딸려 나오는듯은 하구요..
결국은 99번이랑 118번이랑 141번라인 에러를 잡아야한다는데 모르겠습니다...
학교 유닉스 서버에 넣고 돌려보니 전부다 for문뒤에 ';' 요거 세미콜론이 없다고 나오구요 ;; 분명 그담에 블록으로 잡아줬으니 문제가 없을듯한데 도저히 모르겠습니다 :oops: :oops: :oops: :oops: :oops:
이것때문이 아닐까 하시는점 있으시면 좀 알려주십시오;;;

p.s. 음.. code안에서는 볼드못하나보네요 ;;
p.s.2 아직 배우는 입장이니 코드 별로 안이뻐도 양해를 바랍니다 8)

#include<stdio.h>
#include<fcntl.h>
#include<unistd.h>
//define
#define NAMELENGTH	41
#define NROOMS		10

//variable
char namebuf[NAMELENGTH];
int infile = -1;


//Function
char *getoccupier(int roomno);
int findfree(void);
int freeroom(int );
int addguest(int , char * );

int main(int argc, char *argv[])
{
	char command, inputbuf[NAMELENGTH];
	int nroom, i;
	
	if( (infile = open("residents", O_RDWR | O_CREAT)) == -1)
	{
		printf("can't open file");
		exit(1);
	}
	while(1)
	{
		printf("Add guest : a,Free Room : f,Get guest name : g,Quit : q\n");
		printf("input : ");
		command = getchar();

		switch(command)
		{
			case 'a' :
				printf("input Occupier's Name: ");
				i = 0;
				while( (inputbuf[i++] = getchar()) != '\n');
				nroom = findfree();
				addguest(nroom, inputbuf);
				break;
			case 'f' :
				printf("input Room number");
				i = 0;
				while( (inputbuf[i++] = getchar()) != '\n');
				nroom = atoi(inputbuf);
				if(freeroom(nroom))
					printf("can't free room");
				else
					printf("Success free room");
				break;
			case 'g' :
				printf("input Room number");
				i = 0;
				while( (inputbuf[i++] = getchar()) != '\n');
				nroom = atoi(inputbuf);
				if(getoccupier(nroom))
					printf("%s in ROOM %d\n", namebuf, nroom);
				else
					printf("ROOM %d is empty", nroom);
				break;
			case 'q' :
				printf("quit this program bye~");
				close(infile);
				exit(0);
			default :
				break;
		}
		fflush(stdin);
	}
	
}

char *getoccupier(int roomno)
{
	off_t offset;
	ssize_t nread;

	offset = (roomno - 1) * NAMELENGTH;

	// seeking room and reading name
	if( lseek(infile, offset, SEEK_SET) == -1)
		return (NULL);
	if( (nread = read(infile, namebuf, NAMELENGTH)) <= 0)
		return (NULL);

	namebuf[nread-1] = '\0';		//change '\n' to '\0'
	return namebuf;
}

int findfree()
{
	int i = 0;

	for(i = 1, i <= NROOMS, i++ )                  // 여기랑
	{
		getoccupier(i);
		if( namebuf[0] == ' ')
			return i;
	}
	return (-1);
}

int freeroom(int roomno)
{
	int i;
	off_t offset;

	offset = (roomno -1) * NAMELENGTH;
	
	if(lseek(infile, offset, SEEK_SET) == -1)
		return (-1);
	
	for(i = 0, i < NAMELENGTH - 1, i ++)                //여기랑...;;
		namebuf[i] = ' ';
	namebuf[NAMELENGTH-1] = '\n';
	
	if( write(infile, namebuf, NAMELENGTH) != NAMELENGTH)
		return (-1);
	return (0);
}

int addguest(int roomno, char *guest)
{
	int i;
	off_t offset;
	offset = (roomno -1)*NAMELENGTH;

	getoccupier(roomno);
	if(namebuf[0] != ' ')
	{
		printf("ROOM %s is full", roomno);
		return (-1);
	}
	
	
	for(i = 0, i < (NAMELENGTH -1), i++)        //여기입니다
		namebuf[i] = ' ';
	namebuf[NAMELENGTH-1] = '\n';
	i = 0;
	while(guest[i] != '\0')
	{
		namebuf[i] = guest[i];
	}

	if( lseek(infile, offset, SEEK_SET) == -1)
		return (-1); 

	if(write(infile, namebuf, NAMELENGTH) <= 0)
		return (-1);
	
	return 0;
}

Quote:
exam2_9.c: In function `findfree':
exam2_9.c:99: error: parse error before ')' token
exam2_9.c: At top level:
exam2_9.c:105: error: parse error before "return"
exam2_9.c: In function `freeroom':
exam2_9.c:118: error: parse error before ')' token
exam2_9.c: In function `addguest':
exam2_9.c:141: error: parse error before ')' token
익명 사용자의 이미지

for문의 문법을 다시 공부하세요.
for(initial-clause;expression;expression) 이런식입니다.

불량도ㅐㅈㅣ의 이미지

for( , , ) 이런 식으로 쓰셨네요?? :shock:

for( ; ; ) 이렇게 써야 하는데...

문근영 너무 귀여워~~

whitelazy의 이미지

악 ;;;;;;;;;
간만에 프로그래밍하다가 사고쳤군요 ㅡ_ㅡ;;;;;;;;;;;
죽어야지;;;
감사합니다 ㅠ_ㅠ
왜 그걸 못봤는지.......
으으 역시 마음이 조급하면 못보는군요 ㅠ_ㅠ

이거 고치니 컴파일은 되는군요 물론 실행'만'되고 제대로 동작은 안되네요 ㅎㅎ
버그잡아야겠습니다 ;; :oops:

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.