Take the 2-minute tour ×

I have a task to implement "void makeAmbigram(char*)" that will print on screen ambigram of latin string or return something like 'ambigram not possible'. Guess it's just about checking if string contains only of SNOXZHI and printing string backwards. Or am I wrong ?

I'm a complete noob when dealing with cpp so that's what I've created :

#include <iostream>
using namespace std;


char[] ret_str(char* s)
    if(*s != '\0')

    return s;

void makeAmbigram(char* c)
 /* finding chars XIHNOZS and printing ambigram */ 

int main()
   reversed = ret_str(words);
   return 0;

I can reverse string but how to check if my reversed string contains only needed chars ? I've found some function but it's hard or even imposible to implement it for greater amount of chars : www.java2s.com/Code/C/String/Findcharacterinstringhowtousestrchr.htm

share|improve this question
If this is homework, please tag it as such. Also, a definition of "ambigram" would be useful. –  John Dibling Mar 22 '10 at 22:23

2 Answers 2

You need to allocate space in your arrays or use std::vector. The arrays word and reversed are just pointers and no space is allocated. The C++ language does not support dynamic arrays; however, the STL provides std::vector which dynamically allocates space as required.




#define MAX_LETTERS 64
char words[MAX_LETTERS + 1]; // + 1 for terminating nul character ('\0')
char reversed[MAX_LETTERS + 1];


#include <string>
std::string words;
std::string reversed;


#include <vector>
std::vector<char> words;
std::vector<char> reversed;

As far as the ambigram rules go, you need to talk to your instructor. Also, if this is homework, add a tag indicating so.

Hint: The std::string data type has some reverse iterators which may be of use to you.

share|improve this answer

std::string has an entire family of member functions along the lines of find_first_of. You can pass in a string containing all the letters your ambigram test requires, and they'll find whether any of those letters are present in the source string.

The complete list of string functions is available here.

share|improve this answer

Your Answer


