Retry
Retry

Reputation: 159

For loop not getting executed

I have the following code snippet in which I'm trying to print some statements into an XML file:

void parseXML::writeStruct(std::fstream& abc,std::string prnt)
{
    for (map<string,struct structSet>::iterator it = structData.begin();it != structData.end();it++)
    {
      if (((it->second.parent.compare("")==0) && (it->second.written == false)))
      {
        bool write = true;
        if (it->second.type.compare("")==0)
        {
            for (set<std::string>::iterator i = it->second.fields.begin(); i != it->second.fields.end(); i++)
            {
                map<string,struct fieldSet>::iterator fd = fieldData.find(*i);
                if (fd != fieldData.end())
                {
                    std::string type = fd->second.type;
                    map<string,struct structSet>::iterator ntC = structData.find(type);
                    if (ntC != structData.end())
                    {
                        if (ntC->second.type.compare("") != 0)
                        {
                           map<string,struct structSet>::iterator ntC = structData.find(ntC->second.type);
                           if (ntC == structData.end()|| ntC->second.type.compare("")!= 0||ntC->second.written == false)
                           {  
                              continue;
                           }

                        }
                        else
                        {
                            map<string,struct structSet>::iterator ntC = structData.find(ntC->second.type);
                            if (ntC->second.parent.compare(it->second.name))
                            {
                            }
                            else if (ntC->second.written == true)
                            {
                                abc << INDENT << "\t" <<"\t" << "<nonterminal ref= \"" << ntC->second.name.c_str() << "\">" << std::endl;
                                abc << INDENT << "\t" << "\t" <<"\t" << "<name>" << fd->second.name.c_str() << "</name>" << std::endl;
                                abc << INDENT << "\t"<< "\t" << "</nonterminal >" << std::endl;
                            }
                        }
                    }

The problem is that it is not executing the first for loop:

for (map<string,struct structSet>::iterator it = structData.begin(); it != structData.end(); it++)

What are the possible reasons for this?

Upvotes: 0

Views: 120

Answers (1)

Karoly Horvath
Karoly Horvath

Reputation: 96258

Here is a (hopefully) full list, sorry for the obvious entries, but we have no idea how experienced you are:

  • structData is empty
  • structData is corrupted, which crashes the application
  • parseXML::writeStruct was never executed
  • the for loop got executed, but the following (if, for) conditionals failed, and you interpreted this wrongly.

Pick a debugger or add trace messages (don't forget to use endl as output is typically line buffered and will be lost in case of a crash).

Note: post only the relevant part of the code, the rest of it is just noise for us (unless you want a code review for which there is https://codereview.stackexchange.com/)

Upvotes: 2

Related Questions