|
u can use fopen method to open a file like this
<br />
FILE* pFile = fopen("file.txt", "a");<br />
where "file.txt" is the file name and "a" is the mode (Opens for writing at the end of the file (appending))
u can learn more if u look for this function in the MSDN help
use fprintf to write to the file
<br />
fprintf(pFile, "%s\n",szString);<br />
where szString is any Character string !!
note: dont forget to close the file
<br />
fclose(pFile);<br />
|
|
|
|
|
Thanks very much.
Here is the code I've just done, but I can't display the right format
Please give me a fix.
#include <stdio.h>
void display(){
FILE *file1;
int numbers[30];
int i,j;
file1 = fopen("try.txt", "r");
if(file1==NULL) {
printf("Error: can't open file.\n");
}
else {
printf("File opened successfully.\n");
i = 0 ;
while(!feof(file1)) {
fscanf(file1, "%s", numbers[i]);
i++;
}
printf("Number of character read: %d\n\n", i);
printf("The message are:\n");
for(j=0 ; j<i ; j++) {
printf("%s\n", &numbers[j]);
}
}
}
int main() {
FILE *file;
char *array = "eric";
file = fopen("try.txt", "w");
if(file==NULL) {
printf("An error has occurred.\n");
return 1;
}
fprintf(file, "%s\n", array);
display();
fclose(file);
return 0;
}
eric
|
|
|
|
|
eric_tran wrote:
while(!feof(file1)) {
fscanf(file1, "%s", numbers[i]);
i++;
}
%s reads strings, you need numbers (cause you've declared numbers to be a pointer to int), try fscanf(file1, "%d", &numbers[1]);
eric_tran wrote: for(j=0 ; j
printf("%s\n", &numbers[j]);
}
for(j = 0;j<i;j++)
printf("%d ", numbers[j]);
|
|
|
|
|
That's right.
I forgot to change it. I'd actually want to display string only.
Thanks
eric
|
|
|
|
|
easy way (not best)
#include <stdio.h>
int ReadAndStore(char lines[1024][1024])
{
int numberOfLinesRead = 0;
int i;
FILE* theFile = fopen("somefile", "r");
if(theFile==NULL)
return -1;
printf("Opened file for reading\n");
numberOfLinesRead = 0;
while(fgets(lines[numberOfLinesRead],1023,theFile)&&numberOfLinesRead<1024)
{
printf("%s", lines[numberOfLinesRead]);
numberOfLinesRead++;
}
fclose(theFile);
return numberOfLinesRead;
}
int main(int argc, char *argv[])
{
printf("scream if this is to big\n");
char fileContents[1024][1024];
printf("i didn't scream\n");
int i;
int result = ReadAndStore(fileContents);
if(result==-1)
{
printf("Error reading file");
return 1;
}
FILE *out = fopen("outfile","w");
if(out==NULL)
{
printf("Error opening file");
return 1;
}
for(i = 0;i<result;i++)
fputs(fileContents[i],out);
printf("i've read %d lines\n",result);
fclose(out);
return 0;
}
|
|
|
|
|
hello,
i have a 2 classes each have a couple of functions and variable
the problem is: when i want to access a variable from class B inside a function in class A
it come up with Unhandled Exception says:
unhandled exception in "program name": 0xC0000005: Access Violation
<br />
<br />
class A<br />
<br />
{<br />
<br />
<br />
B* p_channel;<br />
<br />
<br />
inline BOOL StartIVR(){ p_channel->m_started = TRUE;
<br />
<br />
}<br />
<br />
class B<br />
<br />
{<br />
<br />
<br />
BOOL m_started ;<br />
<br />
<br />
}<br />
<br />
also any other access to any member in class B will result with the same exception
plz if anybody have any idea abt what's goin' on with this code, feel free to tell me :=)
thnx alot for ur time and concern
|
|
|
|
|
What are you trying to do? Can you show us a little bit more of your code?
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
Define your class B on top A. and see to that you've specified "protected" or "public" to your BOOL m_started;
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
p_channel is an uninitialized pointer. Time to pick up the C++ book.
--
Broadcast simultaneously one year in the future
|
|
|
|
|
the thing is that this p_channel is assigned a value in the construction of the class, meaning that the constructor is responsible for initializing this pointer
so when i call p_channel->"whatever" it is supposed that it is already initialized
|
|
|
|
|
what?? you say B* p_channel then how can it be ?You should've put B* p_channel=new B; Even I didn't notice it.
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
How to initialized p_channel?
|
|
|
|
|
??whitesky?
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
Why
|
|
|
|
|
Your post looked like you are asking how to initialize a pointer
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
wow really
|
|
|
|
|
Yes guys i was wrong
i was passing the pointer to the constructor without initializing it
this is wierd, how did i forget to initialize a pointer.
thnx 4 u help it was really useful. :=)
|
|
|
|
|
Hello everyone,
I am using Visual Studio to create a solution, and in this solution, there are several projects which have dependencies, for example, the output of one project is a DLL and another project will utilize it to build an executable application.
My question is, whether Visual Studio could recognize the dependencies and build projects in correct sequence? Means, building DLL project first, then build the executable application.
If Visual Studio could not, I have to build them manually one-by-one in the correct sequence.
thanks in advance,
George
|
|
|
|
|
I think it should do it automatically according to the sequence it displays in the solution explorer. You can easily test it with the output .exe right?
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
I have tried that I can not change the sequence of projects in one solution in Visual Studio 2003.
regards,
George
|
|
|
|
|
Only if you specified the dependencies (right-click on the solution and select 'Project Dependencies ...').
...cmk
Save the whales - collect the whole set
|
|
|
|
|
I am using Visual Studio 2003, and I can not find a Dependencies or something when I right click a project in Solution Explorer window. Which IDE are you using?
regards,
George
|
|
|
|
|
Yes, you can set the dependencies of various projects within a solution.
In VS8 bring up the "Solution Explorer" (Ctrl+Alt+L)
Right click on the solution, select "Properties" from the popup menu
Under "Common Properties" select "Project Depenencies"
Select the project from the "Project" combobox and select which projects it depends on from the list below.
VS6 and VS7 have the same functionality, but are probably found elsewhere in the IDE.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
Thank you PJ!
I have tried your method and it works! Cool!!!
regards,
George
|
|
|
|
|
Thanks from me too . I'll keep this in mind when I start to use VS8 .
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|