If i have s1[]={"I love bangalore"}; s2[]={"I think bangalore love me and i may love him"}; i need replace each word in s2 which is in s1 with a sufix say-x such that s2 shud become I-x think bangalore-x love-x me and x may love-x him. and count the number of times those three word occur in s2.
It's pretty easy. How far have you got and where are you stuck? Post your code (with code tags) and explain the exact problem.
im tryin 2 convert 1d to 2d...then using a pointer ....point to all the words.....similarly for second string....compare but 1d-2d program isnt workin void main() { char s1[]={"This is my place"},sa[50][10] ; int i=0,j=0,k=0; clrscr(); while(s1[k]!='\0') { if((s1[k]!=' ') || (s1[k]!='\n') || (s1[k]!='\t')) { sa[j]=s1[k]; j++; } else { sa[j]='\0'; i++; j=0; } k++; } sa[j]='\0'; any other idea......can i xtract word by word from a file
Write a C/C++ program which implements the following functionality 1) Read two files simultaneously(we will modify this to make more generic later) 2) File A contains the list of strings and file B is regular text file 3) Read the string mystr(for eg) from File A and search for it in File B 4) Each occurrence of mystr in File B should be replaced with mystr-<suffix> 5) A new File B_Mod should get generated with all the string replaced.
i have a suggestion try separating each word into a different char[] u can use a for loop combined with an if to check for space character (ascii 32) then it should be a piece of cake just compare and add x where they reapeat
Agreed; this is likely to be quite difficult if you try to do this character-by-character. Separate the words into strings, using arrays or vectors to store individual strings, then for each word in the input, check if it exists in the second, then display word or word-x accordingly. By the way, when posting code PLEASE USE CODE TAGS. It's detailed in the posting guidelines. Failure to comply with this probably won't get you banned, but it'll probably get you ignored; if you can't be arsed to use simple code tags, why should we be arsed to help you?
guys so wat do u suggest.........cant i read word by word frm a file and then store it somewhere...... or any out of the blue approach:charming:
Stop talking in txtspk please. You have a full keyboard at your disposal that does not need multiple keypresses for 1 letter, and are not limited to 160 characters. Use sentence structure as well please. If you are already familiar with cin >> var_name; for reading from cin, you can do the same with an istream. You'll need to check your course notes for how your tutor expects you to do file handling.
u can get line by line from a file... using getLine(<filename>,<line>) as i suggested before afterwards u may have to check for the presence of black space to sperate into different words. then do the manipulation to output x, using comparison.
the following is an extract from cplusplus.c om that shows the use of getLine() Code: // reading a text file #include <iostream> #include <fstream> #include <string> using namespace std; int main () { string line; ifstream myfile ("example.txt"); if (myfile.is_open()) { while (! myfile.eof() ) { getline (myfile,line); cout << line << endl; } myfile.close(); } else cout << "Unable to open file"; return 0; } Hope this was helpful .. !!