LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-30-2005, 10:02 AM   #1
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
Large file with c program


When learning about random access files I was presented with this program that I recreated.


What im wondering is why it creates a file that is 768mb is size.


Is this the correct size because when a sizeof is done on just one of these stuctures i get a integer of 44. Im assumeing that 44 is in bytes.



here is the code
Code:
 
#include<stdio.h>

    struct clientdata {
    int acctNum;
    char lastName[15];
    char firstName[20];
    float balance;
    };

int main()
{
	struct clientdata blankclient = {0, "", "", 0.0};
	FILE *cfptr;
	int i; 
	if ((cfptr = fopen("credit.dat", "w")) == NULL)
	   printf("Error opening file for writeing\n");
	else
	{
		for (i = 1; 1 <= 100; i++)
		    fwrite(&blankclient, sizeof(struct clientdata), 1, cfptr);

		fclose(cfptr);
	}

	return 0;
}
 
Old 12-30-2005, 10:18 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
Quote:
Code:
for (i = 1; 1 <= 100; i++)
Check out the red part above. You are checking if one is less-or-equal than hundred, which is of course always the case.

This way you have an endless loop that creates an endlessly growing file.
Replace the '1' (one) with an 'i' (small I), and your program will create a 4400-byte file as expected.
 
Old 12-30-2005, 10:21 AM   #3
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Original Poster
Rep: Reputation: 87
wooops!


LOL I really need to stop writeing code at 3am

thanks sorry for the stupid post.
 
Old 12-30-2005, 10:28 AM   #4
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
I couldn't believe it when you said what the size was, so I ran it and had to abort it. Looking at the following line shows the error.
Code:
 
	for (i = 1; 1 <= 100; i++)
the test will always be true.

<edit>seems i was a little late at posting this, but thanks for making my windows box go belly up

Last edited by dmail; 12-30-2005 at 10:31 AM.
 
Old 12-30-2005, 10:54 AM   #5
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Original Poster
Rep: Reputation: 87
yea the 768mb aparently is the space im allowed on my shell account

when i ran this code in my bochs dos it crashed the os.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Program gets aborted on large input shinni Programming 4 03-12-2005 10:25 PM
how large can a file system be? Wolf_Assassin Linux - Software 2 08-21-2004 03:31 PM
File does not exist/Large file support dreamtheater Linux - General 3 04-19-2004 10:14 AM
An easy way to remove large program groups? KneeLess Debian 6 03-15-2004 09:17 AM
Large tar file taking huge disk space in ext3 file system pcwulf Linux - General 2 10-20-2003 08:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration