• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 09:58
CEST 15:58
KST 22:58
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12TL.net Map Contest #22 - Voting & Ladder Map Selection7Code S Season 2 (2026) - RO8 Preview7[ASL21] Finals Preview: Two Legacies21
Community News
ZeroSpace at Steam NextFest - Last free demo4Weekly Cups (June 8-14): Clem and Solar double, PTR tested0RSL: S6 Finals played at BlizzCon 202611Douyu Cup 2026: $20,000 Legends Event (June 26-28)10[BSL22] Non-Korean Championship from 13 to 28 June4
StarCraft 2
General
Daily SC2 Player Grid - feedback wanted StarCraft II 5.0.16 PTR Patch Notes may 26th TL Poll: How do you feel about the 5.0.16 PTR balance changes? Code S Season 2 (2026) - RO8 Preview Updates to The Core/Core Lite for v5.0.16?
Tourneys
Master Swan Open (Global Bronze-Master 2) GSL CK #4 20-21th June Crank Gathers Season 4: BW vs SC2 Team League Douyu Cup 2026: $20,000 Legends Event (June 26-28) Maestros of The Game 2 announcement and schedule !
Strategy
[G] Having the right mentality to improve
Custom Maps
Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
Mutation # 530 One For All The PondCast: SC2 News & Results Mutation # 529 Opportunities Unleashed Mutation # 528 Infection Detected
Brood War
General
vespene.gg — BW replays in browser Data needed BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion VPN experiences
Tourneys
[Megathread] Daily Proleagues [ASL21] Grand Finals [BSL22] Grand Finals - Sunday 21:00 CEST Escore Tournament StarCraft Season 2
Strategy
Simple Questions, Simple Answers Relatively freeroll strategies Creating a full chart of Zerg builds Why doesn't anyone use restoration?
Other Games
General Games
Stormgate/Frost Giant Megathread ZeroSpace at Steam NextFest - Last free demo Path of Exile Nintendo Switch Thread ZeroSpace Megathread
Dota 2
Looking for a Dota Mentor Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
Vanilla Mini Mafia {D-2} Late to making 20.06.2026 memorable [p]94718
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread [H]Internet/Gaming Cafe Tips and Tricks The Games Industry And ATVI UK Politics Mega-thread
Fan Clubs
The HerO Fan Club! The herO Fan Club!
Media & Entertainment
Movie Discussion! [Req][Books] Good Fantasy/SciFi books [TV/BOOK] *SPOILERS* Game of Thrones Discussion
Sports
2024 - 2026 Football Thread McBoner: A hockey love story TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion Cricket [SPORT]
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread Facing Challenges in Mobile App Development
TL Community
The Automated Ban List
Blogs
How To Predict Tilt in Espor…
TrAiDoS
An Exploration of th…
waywardstrategy
I'm an arrogant trash talke…
FlaShFTW
Gauntlet SC2: A Retrospectiv…
Ctone23
Why RTS gamers make better f…
gosubay
Customize Sidebar...

Website Feedback

Closed Threads



Active: 8818 users

The Big Programming Thread - Page 45

Forum Index > General Forum
Post a Reply
Prev 1 43 44 45 46 47 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
tofucake
Profile Blog Joined October 2009
Hyrule19221 Posts
April 06 2011 16:25 GMT
#881
On April 07 2011 01:24 kuresuti wrote:
Show nested quote +
On April 06 2011 23:54 tofucake wrote:
The solution is &


Could you clarify?

Where's the fun in that?

A hint though: you don't have any way to access data from loadList()
Liquipediaasante sana squash banana
kuresuti
Profile Blog Joined December 2009
1393 Posts
April 06 2011 16:33 GMT
#882
On April 07 2011 01:25 tofucake wrote:
Show nested quote +
On April 07 2011 01:24 kuresuti wrote:
On April 06 2011 23:54 tofucake wrote:
The solution is &


Could you clarify?

Where's the fun in that?

A hint though: you don't have any way to access data from loadList()


Could you give me another hint as to why the process with storing something in names[] works with addName() but not with loadList() aswell? I don't see a difference between the two.
fabiano
Profile Blog Joined August 2009
Brazil4644 Posts
Last Edited: 2011-04-06 16:44:06
April 06 2011 16:43 GMT
#883
On April 06 2011 20:56 kuresuti wrote:

int main()
{
string s[MAX_SIZE];
int i = 0;
loadList(s, "asd.txt"); // This does not want to store the file contents in s[];
}

int loadList(string names[], const string fileName)
{
ifstream f(fileName.c_str());
int p = 0;
string t;

while(!f.eof())
{
getline(f, t); // Tested this multiple times in different ways, it seems to work.
names[p] = t; // I've checked names[p] multiple times after this, and it does store t;
p++;
}

f.close();

return 0;
}

I've removed some unnecessary code from there, to keep it clean. Any ideas as to what could be wrong?


The parameter names is passed by value and not reference, right? Or is it reference because its an array?

I'vent programmed in C/C++ for a while, but if its really passed by value, then you know why it doesnt work, just pass the reference with &
"When the geyser died, a probe came out" - SirJolt
kuresuti
Profile Blog Joined December 2009
1393 Posts
April 06 2011 16:50 GMT
#884
On April 07 2011 01:43 fabiano wrote:
Show nested quote +
On April 06 2011 20:56 kuresuti wrote:

int main()
{
string s[MAX_SIZE];
int i = 0;
loadList(s, "asd.txt"); // This does not want to store the file contents in s[];
}

int loadList(string names[], const string fileName)
{
ifstream f(fileName.c_str());
int p = 0;
string t;

while(!f.eof())
{
getline(f, t); // Tested this multiple times in different ways, it seems to work.
names[p] = t; // I've checked names[p] multiple times after this, and it does store t;
p++;
}

f.close();

return 0;
}

I've removed some unnecessary code from there, to keep it clean. Any ideas as to what could be wrong?


The parameter names is passed by value and not reference, right? Or is it reference because its an array?

I'vent programmed in C/C++ for a while, but if its really passed by value, then you know why it doesnt work, just pass the reference with &


It is passed as reference. It works fine in addName(), which indicates that I am doing it right, or that the compiler is doing it wrong but ending up right :O
fabiano
Profile Blog Joined August 2009
Brazil4644 Posts
April 06 2011 16:54 GMT
#885
Have you tried to use names[p] = &t ?
"When the geyser died, a probe came out" - SirJolt
Uriel_SVK
Profile Joined April 2010
Slovakia427 Posts
Last Edited: 2011-04-06 17:07:02
April 06 2011 17:03 GMT
#886
On April 06 2011 20:56 kuresuti wrote:
+ Show Spoiler +


int main()
{
string s[MAX_SIZE];
int i = 0;
loadList(s, "asd.txt"); // This does not want to store the file contents in s[];
}

int loadList(string names[], const string fileName)
{
ifstream f(fileName.c_str());
int p = 0;
string t;

while(!f.eof())
{
getline(f, t); // Tested this multiple times in different ways, it seems to work.
names[p] = t; // I've checked names[p] multiple times after this, and it does store t;
p++;
}

f.close();

return 0;
}


I've removed some unnecessary code from there, to keep it clean. Any ideas as to what could be wrong?


ok, not a pro in c/c++, but i think the problem might be that you are not returning the value of names[]. You pass s[] to names[], you add lines to names[], but you do not return lines[] to s[].
In c# i would add ref, but I think in c/c++ it is done with pointers.

Or maybe this could work
+ Show Spoiler +


int main()
{
string s[MAX_SIZE];
int i = 0;
s = loadList("asd.txt"); // This does not want to store the file contents in s[];
}

int loadList(const string fileName)
{
string names[MAX_SIZE];
ifstream f(fileName.c_str());
int p = 0;
string t;

while(!f.eof())
{
getline(f, t); // Tested this multiple times in different ways, it seems to work.
names[p] = t; // I've checked names[p] multiple times after this, and it does store t;
p++;
}

f.close();

return names;
}



sorry if it wont help


buhhy
Profile Joined October 2009
United States1113 Posts
April 06 2011 17:04 GMT
#887
On April 05 2011 04:31 Siniyas wrote:
General question for guys with programming experience in java. Is good to learn JSP at this time? I find it very intrigueing and would like to get into it, but all over the it is written, that its dying, since it is now deprecrated as a view for servlets and it seems JSF is taking over.

So what should i learn if i want to get into dynamic web design with java?


JSF is somewhat different in concept from JSP. It's an additional layer above JSP that manages the backing bean-rendering technology bridge for you. JSF manages a lot of stuff like states for you. JSF 1.2 is built upon JSP, while JSF 2.0 has moved onto facelets for rendering, so JSF and JSP are longer very related.

Personally, I like JSF, but I feel it still has quite a way to go, especially with dynamic web design. Using JSF with Javascript is a royal pain in the ass, though JSF 2.0 has fixed a lot of issues.

Definitely learn what JSP + Servlets are, and how they work, but I'd lean towards JSF.
buhhy
Profile Joined October 2009
United States1113 Posts
Last Edited: 2011-04-06 17:14:38
April 06 2011 17:10 GMT
#888
On April 07 2011 02:03 Uriel_SVK wrote:

Show nested quote +
On April 06 2011 20:56 kuresuti wrote:

int main()
{
string s[MAX_SIZE];
int i = 0;
loadList(s, "asd.txt"); // This does not want to store the file contents in s[];
}

int loadList(string names[], const string fileName)
{
ifstream f(fileName.c_str());
int p = 0;
string t;

while(!f.eof())
{
getline(f, t); // Tested this multiple times in different ways, it seems to work.
names[p] = t; // I've checked names[p] multiple times after this, and it does store t;
p++;
}

f.close();

return 0;
}

I've removed some unnecessary code from there, to keep it clean. Any ideas as to what could be wrong?


ok, not a pro in c/c++, but i think the problem might be that you are not returning the value of names[]. You pass s[] to names[], you add lines to names[], but you do not return lines[] to s[].
In c# i would add ref, but I think in c/c++ it is done with pointers.

Or maybe this could work
+ Show Spoiler +


int main()
{
string s[MAX_SIZE];
int i = 0;
s = loadList("asd.txt"); // This does not want to store the file contents in s[];
}

int loadList(const string fileName)
{
string names[MAX_SIZE];
ifstream f(fileName.c_str());
int p = 0;
string t;

while(!f.eof())
{
getline(f, t); // Tested this multiple times in different ways, it seems to work.
names[p] = t; // I've checked names[p] multiple times after this, and it does store t;
p++;
}

f.close();

return names;
}



sorry if it wont help


Arrays ARE pointers in C++. Seems weird that the code doesn't work. He's not missing the reference symbol.
kuresuti
Profile Blog Joined December 2009
1393 Posts
April 06 2011 17:42 GMT
#889
Okay I've made some progress. I had a menu loop running in which I call loadList(), doesn't work. But if I skip the menu loop altogether and just run loadList() in main it DOES work.

I have no clue why..... as I'm typing this I realize I'm stupid. I have a variable which keeps track of how many elements names contains, but I forgot to add the number of elements loaded in the loadList() function, all my other functions use the counter to output the array etc. etc., which happens to be zero after loadList().

I am very sorry for wasting your time

Thanks for the help though!
buhhy
Profile Joined October 2009
United States1113 Posts
April 06 2011 18:06 GMT
#890
On April 07 2011 02:42 kuresuti wrote:
Okay I've made some progress. I had a menu loop running in which I call loadList(), doesn't work. But if I skip the menu loop altogether and just run loadList() in main it DOES work.

I have no clue why..... as I'm typing this I realize I'm stupid. I have a variable which keeps track of how many elements names contains, but I forgot to add the number of elements loaded in the loadList() function, all my other functions use the counter to output the array etc. etc., which happens to be zero after loadList().

I am very sorry for wasting your time

Thanks for the help though!


Paste all your code?
kuresuti
Profile Blog Joined December 2009
1393 Posts
Last Edited: 2011-04-06 18:19:36
April 06 2011 18:16 GMT
#891
On April 07 2011 03:06 buhhy wrote:
Show nested quote +
On April 07 2011 02:42 kuresuti wrote:
Okay I've made some progress. I had a menu loop running in which I call loadList(), doesn't work. But if I skip the menu loop altogether and just run loadList() in main it DOES work.

I have no clue why..... as I'm typing this I realize I'm stupid. I have a variable which keeps track of how many elements names contains, but I forgot to add the number of elements loaded in the loadList() function, all my other functions use the counter to output the array etc. etc., which happens to be zero after loadList().

I am very sorry for wasting your time

Thanks for the help though!


Paste all your code?


+ Show Spoiler [Code] +
#include "Lab3.h"
#include "func.h"

void menuLoop()
{
string names[MAX_SIZE];
//string *names = new string[MAX_SIZE];

int curNum = 0;
char input = 0;

loadList(names, "asd.txt");

while(input != '7')
{
system("cls");

cout << " *** NAMNLISTA ***\n\n 1. Lägg till namn\n 2. Skriv namnlista\n 3. Ta bort namn\n 4. Sortera\n 5. Sök\n 6. Spara\n 7. Avsluta\n\n Välj alternativ: ";
cin >> input;

switch(input)
{
case '1':
addName(names, curNum);
break;

case '2':
outputList(names, curNum);
break;

case '3':
removeName(names, curNum);
break;

case '4':
sortList(names, curNum);
break;

case '5':
searchList(names, curNum);
break;

case '6':
saveList(names, curNum, "asd.txt");
break;

case '7':

break;

default:
cout << endl;
cout << " Ogiltigt menyalternativ!\n\n";
system("pause");
break;
}

}
}

int addName(string names[], int &curSize)
{
system("cls");

string t;

cin.get();

cout << "Skriv in namn: ";
getline(cin, t);

names[curSize] = t;

curSize++;

return 0;
}

int removeName(string names[], int &curSize)
{
system("cls");

string t;

cin.get();

cout << "Skriv in namn: ";
getline(cin, t);

for(int i = 0; i < curSize; i++)
{
if(t == names[i])
{
names[i] = "0";

if(i < curSize - 1)
{
for(int j = i; j < curSize; j++)
{
names[j] = names[j+1];
}
}

i = curSize;
}
}

names[curSize] = "0";
curSize--;

return 0;
}

int searchName(const string names[], const int curSize)
{

return 0;
}

int outputList(const string names[], const int curSize)
{
system("cls");

for(int i = 0; i < curSize; i++)
cout << names[i] << endl;

cout << endl;

system("pause");

return 0;
}

int sortList(string names[], const int curSize)
{
system("cls");

string temp[curSize];
string tmp;

for(int i = 0; i < curSize; i++)
{
temp[i] = names[i];
//strupr((char*)temp[j].c_str());

}


for(int pass = 0; pass < curSize - 1; pass++)
for(int i = 0; i < curSize - 1; i++)
if(temp[i] > temp[i + 1])
{
tmp = names[i];
names[i] = names[i+1];
names[i+1] = tmp;

tmp = temp[i];
temp[i] = temp[i+1];
temp[i+1] = tmp;
}

cout << "Listan sorterad!\n\n";
system("pause");
return 0;
}

int saveList(const string names[], const int curSize, const string fileName)
{
system("cls");
fstream t;

t.open(fileName.c_str(), ios::out);

if(t.is_open())
{
for(int i = 0; i < curSize; i++)
{
t << names[i];

if(i < curSize - 1)
t << endl;
}

cout << "Filen \"" << fileName << "\" är sparad!\n\n";
}
else
{
cout << "Kunde inte skapa filen! \n\n";
return 0;
}

t.close();
system("pause");
return 0;
}

int loadList(string names[], const string fileName)
{
ifstream f(fileName.c_str());
int p = 0;
string t;

while(!f.eof())
{
getline(f, t);
names[p] = t;
p++;
}

f.close();

for(int i = 0; i < 5; i++)
cout << names[i] << endl;

system("pause");
return 0;
}

int searchList(const string names[], const int curSize)
{
system("cls");

string t;
cin.get();

cout << "Skriv in namn: ";
getline(cin, t);

for(int i = 0; i < curSize; i++)
{
if(t == names[i])
{
cout << "Namnet hittades!\n\nDet är på positionen " << i + 1 << " i namnlistan.\n\n";
system("pause");
return 0;
}
}

cout << "Namnet finns inte i listan!\n\n";

return 0;
}

(Most of that code is WIP)
I might aswell post all of it.

All I do in main() is call menuLoop(), and then the code you see takes over from there. curNum in menuLoop() keeps track of the number of elements, as you can see outputList() which I used for checking, loops while i < curNum, and loadList() didn't do anything with curNum so... yeah. To think I've been sitting with this problem for two days makes it hurt even more

EDIT: Might aswell ask while I'm at it. I'm gonna change the system("pause") crap to better stuff later, is there something in the standard library to clear the screen with instead of system("cls")?
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
April 06 2011 18:25 GMT
#892
On April 07 2011 03:16 kuresuti wrote:
Show nested quote +
On April 07 2011 03:06 buhhy wrote:
On April 07 2011 02:42 kuresuti wrote:
Okay I've made some progress. I had a menu loop running in which I call loadList(), doesn't work. But if I skip the menu loop altogether and just run loadList() in main it DOES work.

I have no clue why..... as I'm typing this I realize I'm stupid. I have a variable which keeps track of how many elements names contains, but I forgot to add the number of elements loaded in the loadList() function, all my other functions use the counter to output the array etc. etc., which happens to be zero after loadList().

I am very sorry for wasting your time

Thanks for the help though!


Paste all your code?


+ Show Spoiler [Code] +
#include "Lab3.h"
#include "func.h"

void menuLoop()
{
string names[MAX_SIZE];
//string *names = new string[MAX_SIZE];

int curNum = 0;
char input = 0;

loadList(names, "asd.txt");

while(input != '7')
{
system("cls");

cout << " *** NAMNLISTA ***\n\n 1. Lägg till namn\n 2. Skriv namnlista\n 3. Ta bort namn\n 4. Sortera\n 5. Sök\n 6. Spara\n 7. Avsluta\n\n Välj alternativ: ";
cin >> input;

switch(input)
{
case '1':
addName(names, curNum);
break;

case '2':
outputList(names, curNum);
break;

case '3':
removeName(names, curNum);
break;

case '4':
sortList(names, curNum);
break;

case '5':
searchList(names, curNum);
break;

case '6':
saveList(names, curNum, "asd.txt");
break;

case '7':

break;

default:
cout << endl;
cout << " Ogiltigt menyalternativ!\n\n";
system("pause");
break;
}

}
}

int addName(string names[], int &curSize)
{
system("cls");

string t;

cin.get();

cout << "Skriv in namn: ";
getline(cin, t);

names[curSize] = t;

curSize++;

return 0;
}

int removeName(string names[], int &curSize)
{
system("cls");

string t;

cin.get();

cout << "Skriv in namn: ";
getline(cin, t);

for(int i = 0; i < curSize; i++)
{
if(t == names[i]
{
names[i] = "0";

if(i < curSize - 1)
{
for(int j = i; j < curSize; j++)
{
names[j] = names[j+1];
}
}

i = curSize;
}
}

names[curSize] = "0";
curSize--;

return 0;
}

int searchName(const string names[], const int curSize)
{

return 0;
}

int outputList(const string names[], const int curSize)
{
system("cls");

for(int i = 0; i < curSize; i++)
cout << names[i] << endl;

cout << endl;

system("pause");

return 0;
}

int sortList(string names[], const int curSize)
{
system("cls");

string temp[curSize];
string tmp;

for(int i = 0; i < curSize; i++)
{
temp[i] = names[i];
//strupr((char*)temp[j].c_str());

}


for(int pass = 0; pass < curSize - 1; pass++)
for(int i = 0; i < curSize - 1; i++)
if(temp[i] > temp[i + 1]
{
tmp = names[i];
names[i] = names[i+1];
names[i+1] = tmp;

tmp = temp[i];
temp[i] = temp[i+1];
temp[i+1] = tmp;
}

cout << "Listan sorterad!\n\n";
system("pause");
return 0;
}

int saveList(const string names[], const int curSize, const string fileName)
{
system("cls");
fstream t;

t.open(fileName.c_str(), ios::out);

if(t.is_open())
{
for(int i = 0; i < curSize; i++)
{
t << names[i];

if(i < curSize - 1)
t << endl;
}

cout << "Filen \"" << fileName << "\" är sparad!\n\n";
}
else
{
cout << "Kunde inte skapa filen! \n\n";
return 0;
}

t.close();
system("pause");
return 0;
}

int loadList(string names[], const string fileName)
{
ifstream f(fileName.c_str());
int p = 0;
string t;

while(!f.eof())
{
getline(f, t);
names[p] = t;
p++;
}

f.close();

for(int i = 0; i < 5; i++)
cout << names[i] << endl;

system("pause");
return 0;
}

int searchList(const string names[], const int curSize)
{
system("cls");

string t;
cin.get();

cout << "Skriv in namn: ";
getline(cin, t);

for(int i = 0; i < curSize; i++)
{
if(t == names[i]
{
cout << "Namnet hittades!\n\nDet är på positionen " << i + 1 << " i namnlistan.\n\n";
system("pause");
return 0;
}
}

cout << "Namnet finns inte i listan!\n\n";

return 0;
}

(Most of that code is WIP)
I might aswell post all of it.

All I do in main() is call menuLoop(), and then the code you see takes over from there. curNum in menuLoop() keeps track of the number of elements, as you can see outputList() which I used for checking, loops while i < curNum, and loadList() didn't do anything with curNum so... yeah. To think I've been sitting with this problem for two days makes it hurt even more

EDIT: Might aswell ask while I'm at it. I'm gonna change the system("pause") crap to better stuff later, is there something in the standard library to clear the screen with instead of system("cls")?


Welcome to the wonderful world of debugging. The easiest mistakes are the ones that take forever to fix. I once looked 4 hours for a bug that consisted of a semicolon on the wrong line.
buhhy
Profile Joined October 2009
United States1113 Posts
April 06 2011 18:27 GMT
#893
On April 07 2011 03:25 Morfildur wrote:
Show nested quote +
On April 07 2011 03:16 kuresuti wrote:
On April 07 2011 03:06 buhhy wrote:
On April 07 2011 02:42 kuresuti wrote:
Okay I've made some progress. I had a menu loop running in which I call loadList(), doesn't work. But if I skip the menu loop altogether and just run loadList() in main it DOES work.

I have no clue why..... as I'm typing this I realize I'm stupid. I have a variable which keeps track of how many elements names contains, but I forgot to add the number of elements loaded in the loadList() function, all my other functions use the counter to output the array etc. etc., which happens to be zero after loadList().

I am very sorry for wasting your time

Thanks for the help though!


Paste all your code?


+ Show Spoiler [Code] +
#include "Lab3.h"
#include "func.h"

void menuLoop()
{
string names[MAX_SIZE];
//string *names = new string[MAX_SIZE];

int curNum = 0;
char input = 0;

loadList(names, "asd.txt");

while(input != '7')
{
system("cls");

cout << " *** NAMNLISTA ***\n\n 1. Lägg till namn\n 2. Skriv namnlista\n 3. Ta bort namn\n 4. Sortera\n 5. Sök\n 6. Spara\n 7. Avsluta\n\n Välj alternativ: ";
cin >> input;

switch(input)
{
case '1':
addName(names, curNum);
break;

case '2':
outputList(names, curNum);
break;

case '3':
removeName(names, curNum);
break;

case '4':
sortList(names, curNum);
break;

case '5':
searchList(names, curNum);
break;

case '6':
saveList(names, curNum, "asd.txt");
break;

case '7':

break;

default:
cout << endl;
cout << " Ogiltigt menyalternativ!\n\n";
system("pause");
break;
}

}
}

int addName(string names[], int &curSize)
{
system("cls");

string t;

cin.get();

cout << "Skriv in namn: ";
getline(cin, t);

names[curSize] = t;

curSize++;

return 0;
}

int removeName(string names[], int &curSize)
{
system("cls");

string t;

cin.get();

cout << "Skriv in namn: ";
getline(cin, t);

for(int i = 0; i < curSize; i++)
{
if(t == names[i]
{
names[i] = "0";

if(i < curSize - 1)
{
for(int j = i; j < curSize; j++)
{
names[j] = names[j+1];
}
}

i = curSize;
}
}

names[curSize] = "0";
curSize--;

return 0;
}

int searchName(const string names[], const int curSize)
{

return 0;
}

int outputList(const string names[], const int curSize)
{
system("cls");

for(int i = 0; i < curSize; i++)
cout << names[i] << endl;

cout << endl;

system("pause");

return 0;
}

int sortList(string names[], const int curSize)
{
system("cls");

string temp[curSize];
string tmp;

for(int i = 0; i < curSize; i++)
{
temp[i] = names[i];
//strupr((char*)temp[j].c_str());

}


for(int pass = 0; pass < curSize - 1; pass++)
for(int i = 0; i < curSize - 1; i++)
if(temp[i] > temp[i + 1]
{
tmp = names[i];
names[i] = names[i+1];
names[i+1] = tmp;

tmp = temp[i];
temp[i] = temp[i+1];
temp[i+1] = tmp;
}

cout << "Listan sorterad!\n\n";
system("pause");
return 0;
}

int saveList(const string names[], const int curSize, const string fileName)
{
system("cls");
fstream t;

t.open(fileName.c_str(), ios::out);

if(t.is_open())
{
for(int i = 0; i < curSize; i++)
{
t << names[i];

if(i < curSize - 1)
t << endl;
}

cout << "Filen \"" << fileName << "\" är sparad!\n\n";
}
else
{
cout << "Kunde inte skapa filen! \n\n";
return 0;
}

t.close();
system("pause");
return 0;
}

int loadList(string names[], const string fileName)
{
ifstream f(fileName.c_str());
int p = 0;
string t;

while(!f.eof())
{
getline(f, t);
names[p] = t;
p++;
}

f.close();

for(int i = 0; i < 5; i++)
cout << names[i] << endl;

system("pause");
return 0;
}

int searchList(const string names[], const int curSize)
{
system("cls");

string t;
cin.get();

cout << "Skriv in namn: ";
getline(cin, t);

for(int i = 0; i < curSize; i++)
{
if(t == names[i]
{
cout << "Namnet hittades!\n\nDet är på positionen " << i + 1 << " i namnlistan.\n\n";
system("pause");
return 0;
}
}

cout << "Namnet finns inte i listan!\n\n";

return 0;
}

(Most of that code is WIP)
I might aswell post all of it.

All I do in main() is call menuLoop(), and then the code you see takes over from there. curNum in menuLoop() keeps track of the number of elements, as you can see outputList() which I used for checking, loops while i < curNum, and loadList() didn't do anything with curNum so... yeah. To think I've been sitting with this problem for two days makes it hurt even more

EDIT: Might aswell ask while I'm at it. I'm gonna change the system("pause") crap to better stuff later, is there something in the standard library to clear the screen with instead of system("cls")?


Welcome to the wonderful world of debugging. The easiest mistakes are the ones that take forever to fix. I once looked 4 hours for a bug that consisted of a semicolon on the wrong line.


sad but true...

So, your code works correctly now?
kuresuti
Profile Blog Joined December 2009
1393 Posts
April 06 2011 18:29 GMT
#894
On April 07 2011 03:27 buhhy wrote:
Show nested quote +
On April 07 2011 03:25 Morfildur wrote:
On April 07 2011 03:16 kuresuti wrote:
On April 07 2011 03:06 buhhy wrote:
On April 07 2011 02:42 kuresuti wrote:
Okay I've made some progress. I had a menu loop running in which I call loadList(), doesn't work. But if I skip the menu loop altogether and just run loadList() in main it DOES work.

I have no clue why..... as I'm typing this I realize I'm stupid. I have a variable which keeps track of how many elements names contains, but I forgot to add the number of elements loaded in the loadList() function, all my other functions use the counter to output the array etc. etc., which happens to be zero after loadList().

I am very sorry for wasting your time

Thanks for the help though!


Paste all your code?


+ Show Spoiler [Code] +
#include "Lab3.h"
#include "func.h"

void menuLoop()
{
string names[MAX_SIZE];
//string *names = new string[MAX_SIZE];

int curNum = 0;
char input = 0;

loadList(names, "asd.txt");

while(input != '7')
{
system("cls");

cout << " *** NAMNLISTA ***\n\n 1. Lägg till namn\n 2. Skriv namnlista\n 3. Ta bort namn\n 4. Sortera\n 5. Sök\n 6. Spara\n 7. Avsluta\n\n Välj alternativ: ";
cin >> input;

switch(input)
{
case '1':
addName(names, curNum);
break;

case '2':
outputList(names, curNum);
break;

case '3':
removeName(names, curNum);
break;

case '4':
sortList(names, curNum);
break;

case '5':
searchList(names, curNum);
break;

case '6':
saveList(names, curNum, "asd.txt");
break;

case '7':

break;

default:
cout << endl;
cout << " Ogiltigt menyalternativ!\n\n";
system("pause");
break;
}

}
}

int addName(string names[], int &curSize)
{
system("cls");

string t;

cin.get();

cout << "Skriv in namn: ";
getline(cin, t);

names[curSize] = t;

curSize++;

return 0;
}

int removeName(string names[], int &curSize)
{
system("cls");

string t;

cin.get();

cout << "Skriv in namn: ";
getline(cin, t);

for(int i = 0; i < curSize; i++)
{
if(t == names[i]
{
names[i] = "0";

if(i < curSize - 1)
{
for(int j = i; j < curSize; j++)
{
names[j] = names[j+1];
}
}

i = curSize;
}
}

names[curSize] = "0";
curSize--;

return 0;
}

int searchName(const string names[], const int curSize)
{

return 0;
}

int outputList(const string names[], const int curSize)
{
system("cls");

for(int i = 0; i < curSize; i++)
cout << names[i] << endl;

cout << endl;

system("pause");

return 0;
}

int sortList(string names[], const int curSize)
{
system("cls");

string temp[curSize];
string tmp;

for(int i = 0; i < curSize; i++)
{
temp[i] = names[i];
//strupr((char*)temp[j].c_str());

}


for(int pass = 0; pass < curSize - 1; pass++)
for(int i = 0; i < curSize - 1; i++)
if(temp[i] > temp[i + 1]
{
tmp = names[i];
names[i] = names[i+1];
names[i+1] = tmp;

tmp = temp[i];
temp[i] = temp[i+1];
temp[i+1] = tmp;
}

cout << "Listan sorterad!\n\n";
system("pause");
return 0;
}

int saveList(const string names[], const int curSize, const string fileName)
{
system("cls");
fstream t;

t.open(fileName.c_str(), ios::out);

if(t.is_open())
{
for(int i = 0; i < curSize; i++)
{
t << names[i];

if(i < curSize - 1)
t << endl;
}

cout << "Filen \"" << fileName << "\" är sparad!\n\n";
}
else
{
cout << "Kunde inte skapa filen! \n\n";
return 0;
}

t.close();
system("pause");
return 0;
}

int loadList(string names[], const string fileName)
{
ifstream f(fileName.c_str());
int p = 0;
string t;

while(!f.eof())
{
getline(f, t);
names[p] = t;
p++;
}

f.close();

for(int i = 0; i < 5; i++)
cout << names[i] << endl;

system("pause");
return 0;
}

int searchList(const string names[], const int curSize)
{
system("cls");

string t;
cin.get();

cout << "Skriv in namn: ";
getline(cin, t);

for(int i = 0; i < curSize; i++)
{
if(t == names[i]
{
cout << "Namnet hittades!\n\nDet är på positionen " << i + 1 << " i namnlistan.\n\n";
system("pause");
return 0;
}
}

cout << "Namnet finns inte i listan!\n\n";

return 0;
}

(Most of that code is WIP)
I might aswell post all of it.

All I do in main() is call menuLoop(), and then the code you see takes over from there. curNum in menuLoop() keeps track of the number of elements, as you can see outputList() which I used for checking, loops while i < curNum, and loadList() didn't do anything with curNum so... yeah. To think I've been sitting with this problem for two days makes it hurt even more

EDIT: Might aswell ask while I'm at it. I'm gonna change the system("pause") crap to better stuff later, is there something in the standard library to clear the screen with instead of system("cls")?


Welcome to the wonderful world of debugging. The easiest mistakes are the ones that take forever to fix. I once looked 4 hours for a bug that consisted of a semicolon on the wrong line.


sad but true...

So, your code works correctly now?


Perhaps not correctly, not yet at least. But it works as expected! Thanks again!
Glowbox
Profile Joined June 2010
Netherlands330 Posts
Last Edited: 2011-04-06 18:35:23
April 06 2011 18:34 GMT
#895
On April 07 2011 02:10 buhhy wrote:
Show nested quote +
On April 07 2011 02:03 Uriel_SVK wrote:

On April 06 2011 20:56 kuresuti wrote:

int main()
{
string s[MAX_SIZE];
int i = 0;
loadList(s, "asd.txt"); // This does not want to store the file contents in s[];
}

int loadList(string names[], const string fileName)
{
ifstream f(fileName.c_str());
int p = 0;
string t;

while(!f.eof())
{
getline(f, t); // Tested this multiple times in different ways, it seems to work.
names[p] = t; // I've checked names[p] multiple times after this, and it does store t;
p++;
}

f.close();

return 0;
}

I've removed some unnecessary code from there, to keep it clean. Any ideas as to what could be wrong?


ok, not a pro in c/c++, but i think the problem might be that you are not returning the value of names[]. You pass s[] to names[], you add lines to names[], but you do not return lines[] to s[].
In c# i would add ref, but I think in c/c++ it is done with pointers.

Or maybe this could work
+ Show Spoiler +


int main()
{
string s[MAX_SIZE];
int i = 0;
s = loadList("asd.txt"); // This does not want to store the file contents in s[];
}

int loadList(const string fileName)
{
string names[MAX_SIZE];
ifstream f(fileName.c_str());
int p = 0;
string t;

while(!f.eof())
{
getline(f, t); // Tested this multiple times in different ways, it seems to work.
names[p] = t; // I've checked names[p] multiple times after this, and it does store t;
p++;
}

f.close();

return names;
}



sorry if it wont help


Arrays ARE pointers in C++. Seems weird that the code doesn't work. He's not missing the reference symbol.


This is not true. They might have similar behavior but they're not the same!
(http://www.cplusplus.com/forum/articles/9/)
EscPlan9
Profile Blog Joined December 2006
United States2777 Posts
Last Edited: 2011-04-06 20:59:26
April 06 2011 20:58 GMT
#896
A brief intro before my questions...

Lately I've been concentrating more on my web development skills, which previously were behind my OOP ones. I have a solid grasp of HTML and CSS. I'm also picking up the Adobe Creative Suite (Flash, Photoshop, Premiere, etc) from projects in my Interactive Digital Media Class. However, in my free time I want to learn more about communicating with the server on the web.

Say I want to understand how to implement functions like the end-user submits information to the server, the server processes the information and queries a database I create. What languages should I go for next to better understand how to do this? At the moment my web dev track has gone like this:

HTML > CSS > JavaScript > DOM > ???


PHP, Ruby, Apache, IIS, ASP .NET, C# .NET all have been recommended for what to learn next. I've tried to hone in on PHP using Apache, but haven't gone far yet since setup has been such a pain in the ass. At the moment PHP isn't able to update Apache's httpd config file and I need to lookup how to manually do that (after taking a good amount of time researching how to get Apache working - which it now does).

I guess I have a few questions:

1) What languages should I learn next?

2) Are the options different enough that I should learn both in the end? i.e. ASP.NET vs C#.NET? PHP vs Ruby? Apache vs IIS?

3) Related, but do the different options serve different functions, or is it more of a preference thing?

4) At the moment I am using this for my PHP tutorial: http://devzone.zend.com/node/view/id/627
Because I'm having issues getting PHP properly configured, my test php file just displays its entire contents in plain text (I'm assuming that's the reason I'm not seeing the expected server response). Any suggestions for other tutorials? I didn't see any linked in OP.

I know it's a lot of questions, but I want to know more about what some of you recommend for the next steps given what I want to learn.

edit: formatting changes
Undefeated TL Tecmo Super Bowl League Champion
killanator
Profile Blog Joined January 2008
United States549 Posts
April 07 2011 05:11 GMT
#897
Does anyone have experience in TI-Basic?(the language of texas instrument graphing calculators, i have a ti-84 plus)

I want to program a few functions into my calculator to save time on the ap test(trapezoid rule, riemann sums) as well as reduce the likelihood of me entering something in wrong. What im not sure is how to ask the user for a function and use that function in the program. this is what i tried


:Input"F(X)?Y1


and got a syntax error. and even once i can store it how do i use it in the function to plug x into it? Like im trying to do a for loop for riemann sums and i want to add f(n) to a variable but I dont know how to plug x into the function. The tutorials on the internet arent very helpful, most are very basic or focused on making games.
DJ, put it back on!
EvanED
Profile Joined October 2009
United States111 Posts
Last Edited: 2011-04-07 06:27:41
April 07 2011 06:21 GMT
#898
Ooo, this should be a fun thread.

On April 07 2011 03:34 Glowbox wrote:
Show nested quote +
On April 07 2011 02:10 buhhy wrote:
Arrays ARE pointers in C++. Seems weird that the code doesn't work. He's not missing the reference symbol.


This is not true. They might have similar behavior but they're not the same!
(http://www.cplusplus.com/forum/articles/9/)


I want to expand on this, because I think that article misses a couple differences, and spends some time on stuff you probably don't care about (e.g. the fact that they assembly output differs). I'd recommend this page instead http://www.lysator.liu.se/c/c-faq/c-2.html for more. (The page talks about C, but with minor changes it applies to C++ as well.)

Arrays decay to pointers in C++, meaning there is an automatic conversion, and in some cases they are essentially synonyms (e.g. in a function parameter list), but there is a difference.

#include <iostream>
#include <typeinfo>
using namespace std;

int main() {
const char array[] = "hello world!";
const char * pointer = "hello world!";
cout << "The array says " << array << " and has a size of " << sizeof(array) << " bytes.\n";
cout << "The pointer says " << pointer << " and has a size of " << sizeof(pointer) << " bytes.\n";
cout << "The type of the array is " << typeid(array).name() << "\n";
cout << "The type of the pointer is " << typeid(pointer).name() << "\n";
if (&typeid(array) == &typeid(pointer)) {
cout << "array and pointer have the same type\n";
}
else {
cout << "array and pointer have different types\n";
}
}


Under MSVC 2008, this prints (changed to use the 64-bit compiler):
The array says hello world! and has a size of 13 bytes.
The pointer says hello world! and has a size of 8 bytes.
The type of the array is char const [13]
The type of the pointer is char const * __ptr64
array and pointer have different types

Under GCC 4.6 on Linux, this prints:
The array says hello world! and has a size of 13 bytes.
The pointer says hello world! and has a size of 8 bytes.
The type of the array is A13_c // an Array of 3 Chars
The type of the pointer is PKc // a Pointer to a Konstant Char
array and pointer have different types


A lot of the time you can pretend that arrays and pointers are the same -- but not all the time. And if your mental model is that they are, and you do enough C/C++ programming, you'll probably get bitten by that at some point.
arioch
Profile Joined May 2010
England403 Posts
April 07 2011 06:36 GMT
#899
On April 07 2011 05:58 EscPlan9 wrote:
A brief intro before my questions...

Lately I've been concentrating more on my web development skills, which previously were behind my OOP ones. I have a solid grasp of HTML and CSS. I'm also picking up the Adobe Creative Suite (Flash, Photoshop, Premiere, etc) from projects in my Interactive Digital Media Class. However, in my free time I want to learn more about communicating with the server on the web.

Say I want to understand how to implement functions like the end-user submits information to the server, the server processes the information and queries a database I create. What languages should I go for next to better understand how to do this? At the moment my web dev track has gone like this:

HTML > CSS > JavaScript > DOM > ???


PHP, Ruby, Apache, IIS, ASP .NET, C# .NET all have been recommended for what to learn next. I've tried to hone in on PHP using Apache, but haven't gone far yet since setup has been such a pain in the ass. At the moment PHP isn't able to update Apache's httpd config file and I need to lookup how to manually do that (after taking a good amount of time researching how to get Apache working - which it now does).

I guess I have a few questions:

1) What languages should I learn next?

2) Are the options different enough that I should learn both in the end? i.e. ASP.NET vs C#.NET? PHP vs Ruby? Apache vs IIS?

3) Related, but do the different options serve different functions, or is it more of a preference thing?

4) At the moment I am using this for my PHP tutorial: http://devzone.zend.com/node/view/id/627
Because I'm having issues getting PHP properly configured, my test php file just displays its entire contents in plain text (I'm assuming that's the reason I'm not seeing the expected server response). Any suggestions for other tutorials? I didn't see any linked in OP.

I know it's a lot of questions, but I want to know more about what some of you recommend for the next steps given what I want to learn.

edit: formatting changes


I work as a winform C#/Java developer so I do not have a great deal of experience with web development as a whole, but I can clarify for you on question 2. ASP.NET is a toolkit based on the CLR (Common Language Runtime) so you actually have the option of writing ASP code in any of the .NET programming languages. For future employment though you will have a lot more options if you jump in at the deep end and learn to code C# from the ground up, focusing on client server development. Your best bet is probably to pick up one of the Microsoft Press books, 70-515 is the ASP block MCTS.

Another option is to look at enterprise Java development, there is a lot of work about at the moment for people who have experience working with Spring and Hibernate.

Obviously I am being boring and looking at it from an employment point of view, but for a budding programmer it is important to start looking at what the market needs as early as you can - C# and Java EE coding jobs are currently on the rise.
Patagia
Profile Joined August 2010
United States10 Posts
April 07 2011 09:38 GMT
#900
Random question, I was wondering if any of you knew any programming problem sites such as Project Euler (http://projecteuler.net/index.php?section=problems). I really enjoy the problems on there and I was wondering if any of you knew any sites similar to that. Sorry for the slight deviation from the rest of the thread =)
Prev 1 43 44 45 46 47 1032 Next
Please log in or register to reply.
Live Events Refresh
WardiTV Spring Champion…
11:00
Playoffs
Cure vs SKillous
WardiTV1040
IntoTheiNu 807
TaKeTV 431
TKL 296
LiquipediaDiscussion
CranKy Ducklings
10:00
Master Swan Open #104
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
ByuN 292
TKL 280
Rex 137
Ryung 98
Railgan 83
RushiSC 7
StarCraft: Brood War
Britney 36295
Calm 5982
Shuttle 2187
Mini 1571
firebathero 1081
Soma 912
BeSt 797
Soulkey 522
NaDa 396
ggaemo 308
[ Show more ]
Sharp 171
sorry 74
Hyun 71
Snow 52
Pusan 51
Liquid`Ret 50
Sea.KH 49
[sc1f]eonzerg 47
soO 43
hero 40
ToSsGirL 35
Free 31
HiyA 29
JYJ 24
Hm[arnc] 24
scan(afreeca) 23
Shine 21
IntoTheRainbow 16
Barracks 12
Terrorterran 10
ajuk12(nOOB) 8
Dota 2
qojqva2020
BananaSlamJamma263
Counter-Strike
fl0m5261
byalli460
kRYSTAL_17
Super Smash Bros
Mew2King79
Heroes of the Storm
Khaldor64
Other Games
gofns53775
tarik_tv9916
B2W.Neo796
Lowko518
crisheroes367
DeMusliM296
Pyrionflax280
Trikslyr12
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 15 non-featured ]
StarCraft 2
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Michael_bg 4
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota2113
League of Legends
• Jankos3196
• Nemesis1359
• TFBlade659
Upcoming Events
Big Brain Bouts
2h 2m
Maplez vs eGGz
Reynor vs Solar
WardiTV Spring Champion…
21h 2m
GSL
22h 2m
Maru vs ShoWTimE
Classic vs Reynor
herO vs Lambo
Solar vs Clem
BSL22 NKC (BSL vs China)
1d 5h
XuanXuan vs Jaystar
Mihu vs Messiah
eOnzErG vs Dewalt
Bonyth vs Jaystar
TerrOr vs Messiah
XuanXuan vs Mihu
eOnzErG vs Jaystar
Replay Cast
1d 10h
WardiTV Spring Champion…
1d 21h
GSL
1d 22h
Patches Events
2 days
BSL22 NKC (BSL vs China)
2 days
Dewalt vs Messiah
Bonyth vs Mihu
TerrOr vs XuanXuan
eOnzErG vs Messiah
Jaystar vs Mihu
Dewalt vs XuanXuan
Bonyth vs TerrOr
Replay Cast
2 days
[ Show More ]
WardiTV Weekly
2 days
Monday Night Weeklies
3 days
Sparkling Tuna Cup
3 days
Douyu Cup 2020
5 days
Oliveira vs Trap
Jieshi vs XY
soO vs FanTaSy
TY vs Coffee
The PondCast
5 days
Douyu Cup 2020
6 days
Neeb vs Impact
MacSed vs Cyan
Scarlett vs Kelazhur
INnoVation vs Dear
Liquipedia Results

Completed

KCM Race Survival 2026 Season 2
uThermal 2v2 2026 Main Event
Heroes Pulsing #2

Ongoing

IPSL Spring 2026
Acropolis #4
CSCL: Masked Kings S4
YSL S3
BSL 22 Non-Korean Championship
SCTL 2026 Spring
Maestros of the Game 2
WardiTV Spring 2026
Murky Cup 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026

Upcoming

CSL 2026 Summer (S21)
CSLAN 4
Blizzard Classic Cup 2026
Kung Fu Cup 2026 Grand Finals
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
HSC XXIX
Douyu Cup 2026
BCC 2026
Heroes Pulsing #3
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.