| | |
OS 9.2 freez on new mem alloc ("new" opperator)
| View Poll Results: What is the best OS for programming in C/C++? | |||
| OS 9.2.x | | 0 | 0% |
| OS 10.x.x | | 1 | 25.00% |
| Linux 2.x.x | | 2 | 50.00% |
| Windowes 2000/XP/2003 Server | | 1 | 25.00% |
| Voters: 4. You may not vote on this poll | |||
![]() |
•
•
Join Date: Sep 2003
Posts: 81
Reputation:
Solved Threads: 0
Hello,
I really don't know if this is more of a Mac of C++ question but.. I am doing a loading of a file with
"
short CSVload (char * filename) //called from main
{
//openning a file and checking if it exists
FILE * datafile = NULL;
if ((datafile=fopen (filename, "r"))==NULL)
{
printf ("\nError - no file found");
return -1;
}
//finding size of the file
fseek (datafile,0,SEEK_END);
int filesize = ftell (datafile);
rewind (datafile);
//allocating a string of a size of a file
char * data;
data = new char (filesize+2); //+2 just to be safe
//reading file (I am using getc but I simplified for this post)
fscanf (datafile,"%s", data);
//closing file
fclose (datafile);
//printing the file
printf ("\nThe data is:\n%s",data);
//deleting data
delete [] data;
//returning success
return 0;
}
"
and the program seems to be freezing every time I call this function.. I have asked somebody why this code doesn't work on OS 9.2 on G3 and the answer was that maybe I am allocating onto the system memory since OS9.2 doesn't protect it's memory like win2k or redhat 9.0 linux (my other systems). My compiler is a very old Code Warrior 7.0 Gold Edition (I usually don't use Mac's, nor this version of CW (I am only doing mac now because of my internship)).
If you can, please help,
Thank you in advance,
Ilya
I really don't know if this is more of a Mac of C++ question but.. I am doing a loading of a file with
"
short CSVload (char * filename) //called from main
{
//openning a file and checking if it exists
FILE * datafile = NULL;
if ((datafile=fopen (filename, "r"))==NULL)
{
printf ("\nError - no file found");
return -1;
}
//finding size of the file
fseek (datafile,0,SEEK_END);
int filesize = ftell (datafile);
rewind (datafile);
//allocating a string of a size of a file
char * data;
data = new char (filesize+2); //+2 just to be safe
//reading file (I am using getc but I simplified for this post)
fscanf (datafile,"%s", data);
//closing file
fclose (datafile);
//printing the file
printf ("\nThe data is:\n%s",data);
//deleting data
delete [] data;
//returning success
return 0;
}
"
and the program seems to be freezing every time I call this function.. I have asked somebody why this code doesn't work on OS 9.2 on G3 and the answer was that maybe I am allocating onto the system memory since OS9.2 doesn't protect it's memory like win2k or redhat 9.0 linux (my other systems). My compiler is a very old Code Warrior 7.0 Gold Edition (I usually don't use Mac's, nor this version of CW (I am only doing mac now because of my internship)).
If you can, please help,
Thank you in advance,
Ilya
The code does, indeed, work in windows or linux? Sorry, I'm not all that familiar with any mac development tools.
Dani the Computer Science Gal 
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds

Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
•
•
Join Date: Sep 2003
Posts: 81
Reputation:
Solved Threads: 0
I actually solved that problem. And am quitee further in the program now. I am using fgets () to get the string (each string gets an feof () check) and then am parsing the string fith strtok after duplicating it with a self made (my compiler at General Atomics (internship) is not using std libs unfortunatly so I have to often make my own) strdup(); But I am way oer the loading stage now...
Ilya
P.S.: Thanks for paying attention though
Ilya
P.S.: Thanks for paying attention though
![]() |
Similar Threads
- google "keyword" question (Search Engine Optimization)
- My "if" is not good (C)
- hotmail not showing "from" in inbox (Web Browsers)
- dynamic memory alloc with "new" freezes OS9.2 (C++)
Other Threads in the OS 7 / 8 / 9 Forum
Views: 4084 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for OS 7 / 8 / 9






