파일입출력 ㅠㅠ

djen10의 이미지

#include
#include

void Fileoutput();
void Fileread();
void Showresult();

int main()
{
Fileoutput();
Fileread();
Showresult();

return 0;
}

void Fileoutput()
{
FILE * fp=fopen("text.txt", "rt");
char read[20];

if(fp==NULL)
puts("파일오픈 실패!");
while(feof(fp))
{
while(fgets(read, sizeof(read), fp)!=NULL)
{
fgets(read,sizeof(read),fp);
printf("%s\n", read);
}
}

fclose(fp);
}
void Fileread()
{
FILE *src=fopen("text.txt", "rt");
FILE *des=fopen("output.txt", "wt");
char read[500];

if(src==NULL || des==NULL)
puts("파일오픈 실패!");

while(fgets(read, sizeof(read), src)!=NULL)
fputs(read,des);
}

void Showresult()
{
FILE * fp=fopen("output.txt", "rt");
char read[500];
double result[10];
int i;
int resultcnt=0;
int resultnum=0;
int len=0;

if(fp==NULL)
{
puts("파일오픈 실패!");
}

while(feof(fp))
{
fgets(read,sizeof(read), fp);
for(i=0;read[i]!=NULL;i++)
{
if(read[i]=='#')
resultnum++;
}
len=strlen(read);
result[resultcnt]=len-resultnum/100.00;
resultnum=0;
resultcnt++;

}

resultcnt=0;

while(result[resultcnt]!='\0');
{
printf("%d.Efficiency ratio is %.2f % \n", (resultcnt+1), result[resultcnt]);

resultcnt++;
}
fclose(fp);
}

소스가 이런데요

실행하면 아무것도 뜨지 않네요..

첫번째 함수는 파일을 열고 문자열 단위로 출력하는 겁니다

두번째 함수는 파일을 복사하는 것이고요

세번째 함수는 복사한 파일을 읽어서 문자열의 길이를 알고 그 문자열 안에서 #의 갯수를 알아내어 퍼센트 게이지를 얻는 함수입니다..

어디를 고치고 추가해야 할지 도와주세요

shint의 이미지

//http://www.acm.uiuc.edu/webmonkeys/book/c_guide/
 
#include <windows.h>
#include <stdio.h>
 
 
void Fileoutput ();
void Fileread ();
void Showresult ();
 
 
int main () 
{
	Fileoutput ();
	Fileread ();
	Showresult ();
	system("pause");
	return 0;
}
 
 
//첫번째 함수는 파일을 열고 문자열 단위로 출력하는 겁니다
 
void Fileoutput () 
{
	char read[20];
	char* pchar = NULL;
 
	//FILE *fopen(const char *filename, const char *mode);
	//On success a pointer to the file stream is returned. On failure a null pointer is returned.
	FILE * fp = fopen ("text.txt", "rt");
	if (fp == NULL)
	{
		puts ("파일오픈 실패!");
		return ;
	}
 
	while (1)
    {
		//http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.12.html#feof
		//int feof(FILE *stream);
		//Tests the end-of-file indicator for the given stream.
		//If the stream is at the end-of-file, then it returns a nonzero value.
		//If it is not at the end of the file, then it returns zero.
		if(feof (fp) != 0)
			break;
 
		//
		memset(read, 0x00, sizeof(read));
 
		//char *fgets(char *str, int n, FILE *stream);
		//Reads a line from the specified stream and stores it into the string pointed to by str.
		//It stops when either (n-1) characters are read, the newline character is read,
		//or the end-of-file is reached, whichever comes first.
		//The newline character is copied to the string.
		//A null character is appended to the end of the string.
		//On success a pointer to the string is returned. On error a null pointer is returned.
		//If the end-of-file occurs before any characters have been read, the string remains unchanged.
		pchar = fgets (read, sizeof (read), fp);
		if (pchar == NULL)
		{
			fclose (fp);
			return ;
		}
		printf ("%s", read);
	}
	fclose (fp);
}
 
 
//두번째 함수는 파일을 복사하는 것이고요
 
void Fileread () 
{
	char read[500];
	char* pchar = NULL;
  	FILE * fp_src = fopen ("text.txt", "rt");
	FILE * fp_des = fopen ("output.txt", "wt");
 
	if (fp_src == NULL)
	{
		puts ("src 읽기 파일 열기 실패!");
		return ;
	}
	if (fp_des == NULL)
	{
		fclose (fp_src);
		puts ("des 쓰기 파일 열기 실패!");
		return ;
	}
 
	while (1)
	{
		if(feof (fp_src) != 0)
			break;
 
		//
		memset(read, 0x00, sizeof(read));
 
		//
		pchar = fgets (read, sizeof (read), fp_src);
		if (pchar == NULL)
		{
			fclose (fp_src);
			fclose (fp_des);
			return ;
		}
		fputs (read, fp_des);
		printf ("%s", read);
	}
	fclose (fp_src);
	fclose (fp_des);
}
 
 
//세번째 함수는 복사한 파일을 읽어서 문자열의 길이를 알고 그 문자열 안에서 #의 갯수를 알아내어 퍼센트 게이지를 얻는 함수입니다..
 
void Showresult () 
{
	int i			= 0;
	int len			= 0;
	int resultcnt	= 0;
	int resultnum	= 0;
	double value	= 0.0;
	double result[10];
	char read[500];
	char* pchar = NULL;
	FILE * fp = fopen ("output.txt", "rt");
	if (fp == NULL)
	{
		puts ("파일오픈 실패!");
		return ;
	}
 
	while (1)
	{
		if(feof (fp) != 0)
			break;
 
		//
		pchar = fgets (read, sizeof (read), fp);
		if (pchar == NULL)
		{
			fclose (fp);
			return ;
		}
 
		//
		for (i = 0; read[i] != NULL; i++)
		{
			if (read[i] == '#')
				resultnum++;
		}
		len = strlen (read);
		value = (double)(len - resultnum);
		if(value == 0.0)
		{
			result[resultcnt] = 0.0;
		}
		else
		{
			result[resultcnt] = value / 100.00;
		}
		resultnum = 0;
		resultcnt++;
	}
	resultcnt = 0;
 
	while (result[resultcnt] != '\0');
	{
		printf ("%d.Efficiency ratio is %.2f % \n", (resultcnt + 1), result[resultcnt]);
		resultcnt++;
	}
	fclose (fp);
}

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

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