Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   HELP!!!!-c/c++ (http://www.go4expert.com/forums/help-c-cpp-t20053/)

tupandey 11Nov2009 11:17

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.

xpi0t0s 11Nov2009 14:19

Re: HELP!!!!-c/c++
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.

tupandey 11Nov2009 15:06

Re: HELP!!!!-c/c++
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;
if((s1[k]!=' ') || (s1[k]!='\n') || (s1[k]!='\t'))

any other idea......can i xtract word by word from a file

tupandey 11Nov2009 15:14

Re: HELP!!!!-c/c++
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.

dennyphilip 11Nov2009 15:43

Re: HELP!!!!-c/c++
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 :)

xpi0t0s 11Nov2009 16:02

Re: HELP!!!!-c/c++
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?

tupandey 11Nov2009 16:14

Re: HELP!!!!-c/c++
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:

xpi0t0s 11Nov2009 16:32

Re: HELP!!!!-c/c++
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.

dennyphilip 11Nov2009 18:20

Re: HELP!!!!-c/c++
u can get line by line from a file... using
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.

dennyphilip 11Nov2009 18:23

Re: HELP!!!!-c/c++
the following is an extract from cplusplus.c om that shows the use of getLine()

// 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;

  else cout << "Unable to open file";

  return 0;

Hope this was helpful .. !!

All times are GMT +5.5. The time now is 21:01.