I have a list having m1 m2 m3........ m922

and in each there are a1 a2 a3 a4 are there like
m1=a1 a2 a3 a4 a5 a6
m2=a1 a2 a3 a4 a5 a6
m3=a1 a3 a5 a7 a8 a2


and i want this as

m1=a1 a2 a3 a4 a5 a6
a2 a3 a4 a5 a6 a1
a3 a1 a2 a4 a5 a6
a4 a1 a2 a3 a5 a6
m2 =a1 a2 a3 a4 a5 a6
a2 a3 a4 a5 a6 a1
a3 a1 a2 a4 a5 a6
a4 a1 a2 a3 a5 a6

and so on please help

Duplicate post, and we don't do your homework for you!
2 Years
Discussion Span
Last Post by Labdabeta

Have you even tried to do YOUR assignment by yourself yet? For your sake, try to code this and then post the code where you think you are having the troubles.


yes I have tried it but only thing i was able to do is to get text file in and to store it in array and simply print it nothing els im getting of it


Maya Machhindar#G Timbe#Durga Khote#Vinayak#Mohini#Baburao Pendharkar#Leela#Purohit#Nimabalkar#Hira Bai#

#include <iostream>
#include <string>
#include <sstream>
#include <fstream>

 int main(){
    //load the text file and put it into a single string:
    std::ifstream in("test.txt");
    std::stringstream buffer;
    buffer << in.rdbuf();
    std::string test = buffer.str();
    std::cout << test << std::endl << std::endl;

    //create variables that will act as "cursors". we'll take everything between them.
    size_t pos1 = 0;
    size_t pos2;

    //create the array to store the strings.
    std::string str[50];

    for (int x=0; x<=20; x++){
        pos2 = test.find("#", pos1); //search for the bar "|". pos2 will be where the bar was found.
        str[x] = test.substr(pos1, (pos2-pos1)); //make a substring, wich is nothing more 
                                              //than a copy of a fragment of the big string.
        std::cout << str[x] << std::endl;
       // std::cout << "pos1:" << pos1 << ", pos2:" << pos2 << std::endl;
      pos1 = pos2+1; // sets pos1 to the next character after pos2. 
                         //so, it can start searching the next bar |.

First of all that is C++, not C. Second your problem description is poor, however I think I understand what you are after.

Of interest is this code snippet:

//This code returns the n'th cycle of string s
std::string tmp;
for (int i=0; i<s.length(); ++i)

The way it works is by starting at an arbitrary position, then 'wrapping-around' back to the start of the string using the modulo operator.

If you get some code to compile, but its giving the wrong result, then maybe we can help you some more.

Good on you for figuring this out...
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.