No, that's to easy... besides how will I learn pointers if I don't use them.
No, that's to easy... besides how will I learn pointers if I don't use them.
Last edited by drdroid; 08-01-2003 at 06:38 AM.
This thread is hilarious!!!!!!!!!!
I'm sure this has all been pointed out already, but here's another try.
> for(int lp=0;lp!=30;lp++)
This should be:
for(int lp=0;lp<30;lp++)
> data.get(*programs[lp]);
Try getline() and take off the star:
data.getline(programs[lp],21);
> strcpy(programs[lp],&"EMPTYSLOT ");
This should be:
strcpy(programs[lp],"EMPTYSLOT ");
> cout << *programs[1];
This should be:
cout << programs[1];
Or if you want the first string:
cout << programs[0];
Last edited by swoopy; 07-31-2003 at 07:10 PM.
all of that's already in the program... and I dun want getline, I'm doing word by word not line by line. Nothing has been solved.
Since nothing here seems to be helping you maybe look at this link it helped me to understand pointers...
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
I haven't seen any problems with my POINTERS THAT'S THE PROBLEM... FWOIIII... sorry, excuse my outburst. But seriously, i know pointers, i just don't know what's wrong, i never stated that my problem was with my pointers, I've done everything you've told me to and it hasn't helped.
edit: so I'm going to erase anything having to do with that god damn variable and I'm going to start from god damn scratch.
seriously, it's good to try challenging things to help you learn, but I think you're out of your depth on this one Dr. Droid.
You don't seem prepared to listen to people's advice anyway
Thor's self help tip:
Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.
OS: Windows XP
Compiler: MSVC
Why don't you post your code (without ANY type casts), highlight each line (use [ color=red ] and [ /color ] tags to highlight a line) that gives a compilation error, and explain in words what each variable is supposed to be and what the goal of the program is.
Without knowing what you're trying to accomplish, how are we to know how to advise? For example:
char* programs[30][21];
This creates 630 pointers (presumably for strings of some kind) but allocates no memory for the strings themselves. Were you trying to allocate memory for 30 strings that are 21 characters long? That isn't what happened.
I've narrowed all of the errors down to mainly this:
with and without the & before data. And about that other stuff was; how else was I going to practice pointers :p .Code:&data.get(programs[lp]); &data.get(programs[lp],20);
what makes you think that? I've tried everything that's been posted here. Despite what you may think I have, and even read that thing on pointers. I understand pointers in concept, and I think I know them in syntax... I've tried going through it to make sure there was a pointer, "pointee", a refrence etc.seriously, it's good to try challenging things to help you learn, but I think you're out of your depth on this one Dr. Droid.
You don't seem prepared to listen to people's advice anyway
Heres the code now:
Code:#include <iostream> #include <fstream> #include <conio.h> using namespace std; char proglist[31][21]; char (*programs)[31][21]; bool charcheck(char* first, char* second) { bool success=true; int lp=0; for(;;) { if(first[lp]!=second[lp]) { success=false; break; } else if(first[lp]=='\0' && second[lp]!='\0') { success=false; break; } else if(first[lp]!='\0'&& second[lp]=='\0') { success=false; break; } else if(success==true && first[lp]=='\0' && second[lp]=='\0') { break; } lp++; } return success; } int main() { programs=&proglist; ifstream data("proglist.txt"); for(int lp=0;lp<=30;lp++) { &data.get(programs[lp][0],20); if(charcheck(programs[lp][0]," ")==true) { cout << "test"; strcpy(programs[lp][0],&"EMPTYSLOT "); } } data.close(); cout << programs[1]; getch(); return 0; }
Last edited by drdroid; 08-01-2003 at 07:07 AM.
With that, now I'm starting to get that it's performing illegal operations.
Edit:
COREWARS caused an invalid page fault in
module COREWARS.EXE at 0167:00404899.
Registers:
EAX=006bfdb8 CS=0167 EIP=00404899 EFLGS=00010246
EBX=005b0000 SS=016f ESP=006bfc04 EBP=006bfc94
ECX=0048111f DS=016f ESI=8196900c FS=20e7
EDX=006bfdb8 ES=016f EDI=006bfc84 GS=0000
Bytes at CS:EIP:
c6 01 00 8b 45 ec 8b 4d f4 64 89 0d 00 00 00 00
Stack dump:
006bfcf8 8196900c 005b0000 cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc
Edit2: BTW, i changed the latest sourcecode on page 2.
I'll echo what Salem said above.
Please describe in words what you want to happen. For instance, do you want to read the file char by char and place a pointer to each char or line by line or ... ?
Also please add part or all of the file "proglist".
Well, I used error flagging and found that it got all the way to here and then crashed.
for(int lp=0;lp<=30;lp++)
{
&data.get(programs[lp][0],20);
if(charcheck(programs[lp][0]," ")==true)
{
cout << "test";
strcpy(programs[lp][0],&"EMPTYSLOT ");
}
HERE
}
data.close();
edit: and this is the file... btw, I'm changing the code on page two again.
Lol, i plan on changing the file once I get everythign running. Basically what I'm doing is loading a file that lists words, I'm loading thoughs words into an array(proglist) which I am pointing to with *program.Code:this is a test
Last edited by drdroid; 08-01-2003 at 07:06 AM.
A bit vauge description.Basically what I'm doing is loading a file that lists words, I'm loading thoughs words into an array(proglist) which I am pointing to with *program.
If the contest of your file is
Do you want one pointer to "this", another pointer to "is" etc... or do you want one pointer to 't' then another to 'h' and 'i' and 's' etc ? Im still not totally getting this...Code:this is a test
I loop through the array, that part of the array takes this, the next part of the array takes is the next part takes a and the next part takes test. Before all of that I create a pointer and the array, then I make a refrence from the pointer to the array.
I just reread the entire thread for the 3rd or 4rth time and I've done everything you've told me to except forget about the pointers and do it another way.you repeatedly make the same mistakes and basically ignore everything everyone says
take it easy on the little guy. he's just a kid
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter