what should i do??help me please
dkwantee 23 Newbie Poster
Ancient Dragon commented: Thanks for taking the time to read the rules and use code tags correctly :) +23
what should i do??help me please
for (i = 0; i < ntokens; i++)
{
puts(words[i]);
}
return(0);
i think this line stores the tokens in an array rite>
I dont know how to use that..:(
do you know how to use the Getnexttoken?
Hello! The text file is separated by tabs..I have used a struc as below:
struct scores
{ int maths
int phy;
int bio;
int chem;
int eng;
int total;
};
struct class
{ int class_id;
char name[50];
};
ifstream fin;
fin.open("marks.txt");
char buf[100];
string a;
getline(fin,a);
char delims[] = "\t";
for(int i=0; i<a.size(); i++)
{
buf[i] = a[i];
}
char *result = NULL;
result = strtok( buf, delims );
while( result != NULL ) {
printf( "result is \"%s\"\n", result );
result = strtok( NULL, delims );
}
when i compile i get: (I have just read one line of the text file)
result is 67
result is 34
result is 34
result is 90
result is 67
result is 76
result is 2
result is Science_G
Now i need to store each column(eng marks,phy marks,..) in an array
as i need to sort them later..
I think i have to use getnexttoken..
can someone guide me how to do it?
Hello!
i want to know if it is possible to create two drop down list and add code such that when a user select a value from the first drop down, he cannot select the same value from the second one..?
i have corrected my code..dont you think it will be too lengthy if i do it this way? is there another way to do that...?
I have to write code for 2 players,same for 3 and 4 players..
Hello everyone,
I need to write code such that:
.you can select number of players(2,3or4) and put that number in array..
.display message if correct number not entered.
.then each player must be able to choose their color(red, blue, yellow,green)
.two players cannot be assigned the same colour
This is what i have done.. Can someone tell me if it is the right way to do this? its a bit length...
int num_players,p1color,p2color,p3color,p4color;
char player_color;
int players[1];
bool selectred,selectblue,selectyellow,selectgreen;
cout<<"Select number of players: ";
cin>>num_players;
players[0]=num_players;
if((num_players>=2) && (num_players<=4))
{ switch(num_players)
{ case 2:
cout<<"Player 1, Choose your house(R for Red,B for Blue,Y for Yellow,";
cout<<"G for Green" <<endl;
cin>>p1color;
if(p1color=='R' || 'r')
{ cout<<"Player 1 is initialised Red";
selectred=true;
selectblue=false;
selectyellow=false;
selectgreen=false;
}
else if(p1color=='B' || 'b')
{ cout<<"Player 1 initialises Blue" ;
selectred=false;
selectblue=true;
selectyellow=false;
selectgreen=false;
}
else if(p1color=='Y' || 'y')
{ cout<<"Player 1 initialises Yellow" ;
selectred=false;
selectblue=false;
selectyellow=true;
selectgreen=false;
}
else if(p1color=='B' || 'b')
{ cout<<"Player 1 initialises Green" ;
selectred=false;
selectblue=false;
selectyellow=false;
selectgreen=true;
}
}
}
//case 2..
cout<<"Error!Please enter a valid number of players(2,3 or 4)" <<endl;
cout<<"Select number of players: ";
cin>>num_players;
players[0]=num_players;
i have not written anything yet..i wanted to get some help on string tokenizer. i know i have to use this to read my file but i dont know how. do you have any simple examples on it?
hello!
I want to know about string tokenizer. i have a file of the following format:-
Studentname StudentID Studentgrades
each is separated by a tab. and the size of the file is unknown. I have to read each line using string tokenizer..Well, i dont know much about this, can someone help me?
i have tried to read 1 line from a file,and it works. but how to read a whole file if the number of lines in unknown?
if i have to sort the scores in maths, do i have to copy it to an array then sort it?
Hello!
i have the following data in a file
student_id student_name maths_score english_score physics_score
can i use a nested structure to read the file?
struct student
{ int id;
char name[40];
};
struct score
{ int maths;
int english;
int physics;
};
if yes, how will i read the file into the structure?help me please
[LIST=1]
[*]void selectionsort(int numbers[],int arraysize)
[*]{ int i,indes,large,j;
[*] for(i=arraysize-1;i>0;i--)
[*] { large=numbers[0];
[*] index=0;
[*] for(j=1;j<=1;j++)
[*] { if(numbers[j]>large)
[*] { large=numbers[j];
[*] index=j;
[*] }
[*] }
[*] numbers[index]=numbers[i];
[*] numbers[i]=large;
[*] }
[*]}
[/LIST]
i have been able to understand upto 7 line. can someone help me further?
i think i=3 at that line..:-/
i have the integers 100 5 5 9 in my array numbers.But when i compile this program i get 2009312941!! Please help me
int main()
{
int numbers[4];
int i;
ifstream streamin;
streamin.open("input.txt");
for(i=0;i<4;i++)
{streamin >> numbers[i] ;
}
cout << numbers[i];
streamin.close();
Hello!
I am having problems to copy the output of a text file to another one. The aim of this small program is to convert a sentence in lowercase stored in a file to uppercase and store the output to another txt file. finally display the output..Plz help me
#include <cstdlib>
#include <iostream>
#include <fstream.h>
using namespace std;
int main()
{
int i ;
char sentence[100];
ifstream streamin;
fstream streamout;
streamin.open("test.txt");
cout<< " The sentence in lowercase letters is: " ;
streamin.getline(sentence,100);
cout<< sentence <<endl;
streamout.open("test2.txt");
cout<< " The sentence in uppercase letters is: " ;
streamin.getline(sentence,100);
for(i=0;sentence[i]!=0;i++)
{ toupper(sentence[i]);
}
ofstream.streamin("test.txt");
system("PAUSE");
return EXIT_SUCCESS;
}
this is where i have reached..