|
You are going to have to get more specific on what's not working, are you able to open the file? Posting the whole program would probably help.
|
|
|
|
|
|
Just put the file.get into a while statement.
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char singlecharacter ;
ifstream file ("vurudi.txt");
file.is_open() ;
while(file.get(singlecharacter))
{
cout<<singlecharacter;
}
file.close();
cout<<"\n\n\n";
return 0;
}
|
|
|
|
|
There are a number of ways to do this depending on your preference and setup of C++ program
Using standard windows API:
HANDLE Handle;
char Ch;
unsigned long Li;
Handle = CreateFile("c:\\yourfile.txt",
GENERIC_READ, 0, 0, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0);
if (Handle != INVALID_HANDLE_VALUE){
ReadFile(Handle, &Ch, 1, &Li, 0);
}
CloseHandle(Handle);
Using the standard ifstream unit:
#include <fstream>
char Ch;
ifstream myFile;
myFile.open("c:\\yourfile.txt");
if (myFile.is_open()) {
myFile.read(Ch, sizeof(Ch));
}
myFile.Close();
Using the standard MFC CFile assuming you are using MFC:
UINT nActual = 0;
char Ch;
CFile myFile;
if ( myFile.Open( _T("c:\\yourfile.txt"), CFile::modeRead | CFile::shareDenyWrite ) )
{
nActual = myFile.Read( Ch, sizeof(Ch) );
}
myFile.Close();
|
|
|
|
|
|
MalDrHoop wrote: I have a C program I just posted some minutes ago.
Not that I can see.
|
|
|
|
|
Thank you for looking it over. I dont know why it isnt giving me the desired results.
|
|
|
|
|
Please give this[^] a read, as I have no idea what you have or want.
|
|
|
|
|
I have skimmed through those. The problem is, I can't find a problem with my program. Idk what is going on unless I haven't made a mistake and just misunderstood the professor. I just know that my program fails after many iterations and it shouldn't take many to achieve the desired result.
Thank you for your time anyways
|
|
|
|
|
MalDrHoop wrote: The problem is, I can't find a problem with my program
You haven't asked a specific question.
You haven't posted any code.
And possibly worst of all, you used text speak.
MalDrHoop wrote: I have skimmed through those.
Apparently not well enough.
|
|
|
|
|
Actually, sir, you apparently did not read my original question. In it I asked for someone to go to where I had posted a question and check it out.
|
|
|
|
|
MalDrHoop wrote: where I had posted a question
Please point this out to me in your original post, the where part I mean. It is customary to post the code here.
|
|
|
|
|
I am new to these discussion boards. This is my first one. I thought questions were posted under the designated questions area where there is a dropdown box in the top right corner next to your username. Whenever you go to someones profile there is an option to look at their questions and answers, etc. I added a direct link.
|
|
|
|
|
|
MalDrHoop wrote: This would have been as simple as clicking on my name
No, it would have been simple if you posted the code here. Why would I click on your name, how is your name relevant to anything c or c++ related? [Edit] And you're cross posting?
|
|
|
|
|
As I said: I am new to these discussion boards. This is my first one. I thought questions were posted under the designated questions area where there is a dropdown box in the top right corner next to your username. Whenever you go to someones profile there is an option to look at their questions and answers, etc. I added a direct link.
Apparently guidance is not something you are willing to give. Just insults. Which is something that was in the how to answer questions post if I am not mistaken. I specified that I was new to the discussion boards. my program question is way too long to post on here anyways. I was just posting on here to raise awareness of my question. That is posted in the formal questions area. I thought questions belonged in the Questions area. That is what my deduction told me.
|
|
|
|
|
MalDrHoop wrote: As I said: I am new to these discussion boards. Then you should read http://www.codeproject.com/Messages/2922875/HOW-TO-ASK-A-QUESTION.aspx[^] rather than getting angry with someone who is merely trying to understand your original post.
MalDrHoop wrote: I was just posting on here to raise awareness of my question. That is posted in the formal questions area. This is the formal question area. post in one place only.
Veni, vidi, abiit domum
|
|
|
|
|
I did not get angry until he started making fun of me. This is labeled discussions. The other place is labeled Questions. it made more since to place my question in questions. especially as long as it is.
Richard MacCutchan wrote: This is the formal question area. post in one place only.
I did not post my question in two places. Just asked that someone would go take a look at my question. I just stumbled upon the discussion boards today and noticed people pay more attention to it, after I had already posted my question.
|
|
|
|
|
MalDrHoop wrote: I did not get angry until he started making fun of me. He did not make fun of you. He tried very hard to get you to explain what your problem was, which you never did.
MalDrHoop wrote: it made more since to place my question in questions. Fine, but you did not need to start a discussion about it here; that serves only to confuse.
MalDrHoop wrote: I did not post my question in two places. Posting a message here that points to a question elsewhere is considered the same as posting it twice.
Veni, vidi, abiit domum
|
|
|
|
|
The laughing at me smiley face, etc. Wasnt making fun? Ok.I did explain. I posted a direct link straight to my problem. I was unaware discussions were for questions too. I only posted the discussion to raise awareness of my question. I did not realize I was doing something wrong. And if you did in fact read through the whole thread you would see that I mentioned that on multiple occasions. I am new to this site and those of you who are not should just guide others and explain processes to them if they dont quite get it. Not attack them over and over again.I still don't see how posting a link to a question is posting it twice, just gives another access point. Now, please stop attacking me and go on about your business. I will not post here after this thread again for quite some time if ever. I will stick to the area labeled questions.
|
|
|
|
|
MalDrHoop wrote: The laughing at me smiley face, etc. Wasnt making fun? No.
MalDrHoop wrote: I was unaware discussions were for questions too. Did you read http://www.codeproject.com/Messages/2922875/HOW-TO-ASK-A-QUESTION.aspx[^]?
MalDrHoop wrote: And if you did in fact read through the whole thread you would see that I mentioned that on multiple occasions. Not clearly.
MalDrHoop wrote: I still don't see how posting a link to a question is posting it twice Because that is the protocol here. If you post a question in one place and then post somewhere else pointing to the question you are adding unnecessary clutter to the forums.
MalDrHoop wrote: Now, please stop attacking me and go on about your business. No one is attacking you, we are just trying to expalin how this site works.
Veni, vidi, abiit domum
|
|
|
|
|
A laughing smiley face is making fun.
I did look over that briefly, after realizing it was at the top of the forum. My question doesn't seem suitable for a thread if you ask me. Have you seen the size of it? It contained two codes, inputs, and outputs for 100 iterations. And my deduction still would say now that posting a question so large would not be appropriate for a thread.
I did clearly say many times that I was new and unsure how to use threads after I saw that he misunderstood. His first reply seemed to me like he had looked at my program and I didn't catch otherwise till later on. I had asked if anyone could see any problems with my program and his reply was not that I can see. So I thought he had seen it and didn't find an issue.
I don't see how trying to get someone's attention directed to a question that required some much needed help was such an addition of clutter.
When you keep on my case with harshness instead of kind guidance then yes that is attacking in my book.
|
|
|
|
|
MalDrHoop wrote: A laughing smiley face is making fun Not in this forum; it indicates that the writer is not being too serious.
MalDrHoop wrote: I don't see how trying to get someone's attention directed to a question that required some much needed help was such an addition of clutter. Because it is an unnecessary message. All questions can be viewed by all members, and will be answered as and when someone has something useful to respond. If everyone who posted questions added messages such as you did, then the forums would be overflowing with messages that just add confusion.
MalDrHoop wrote: When you keep on my case with harshness Is it harshness to try and explain the proper way of using these forums?
Veni, vidi, abiit domum
|
|
|
|
|
And those desired results are what? Have you stepped through it using the debugger?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi everyone,
Right now, I am creating a project in C and at some point I am accessing, multi times during the source code, to a struct with a lot of nested structs, like this
struct1->struct2->struct3->struct4->struct5->value1
struct1->struct2->struct3->struct4->struct6->value2
What I created was a macro to clear the code:
#define ACCESS (struct1->struct2->struct3->struct4)
ACCESS->struct5->value1
ACCESS->struct6->value2
My question is: This is a good practice or a very very very bad practice?
Best regards,
Filipe Marques
|
|
|
|