473,411 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

can not rectify the problem, initialization of file skipped by case label.

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<string>
  3. #include<iomanip>
  4. #include<fstream>
  5. #include"directory.h"
  6. #include"mylog.h"
  7.  
  8. using namespace std;
  9. // function to input the word to be searched
  10. string input(void)
  11. {
  12. string wordin;
  13. cout<<"enter a word to be searched"<<endl;
  14. cin>>wordin;
  15. return wordin;
  16. }
  17. // function to count the number of times word occured
  18. int count(string temp,string wordtofind)
  19. {
  20.     int counter=0;
  21.     ifstream file;
  22.     string word;
  23.     //file.open("D:\\aroob.txt",ios::in);
  24.     //cout<<file;
  25.     file.open(temp.c_str(),ios::in);
  26.     if(file)  
  27.        {
  28.         while(file >> word)
  29.         {   
  30.             if(word.compare(wordtofind) == 0)
  31.             counter++;
  32.         }
  33.     }
  34.     file.close(); //always pays to be tidy
  35.     return counter;
  36. }
  37. // count func ends
  38. // search by filename
  39. void search (void)
  40. {string name;
  41. int j;
  42. int d;
  43.     char arr[10][50]={"file1.docx","file2.txt","file3.xls","file4.txt"};
  44. cout<<"Enter the name of the file along with the extension to be searched."<<endl;
  45. cin>>name;
  46. if( (name.compare("abcd")==0)||(name.compare("abcdefghijklmnopqrst")==0)||(name.compare("aaaaaaa")==0)||(name.compare("bbbb")==0))
  47. cout<<"Enter a valid name."<<endl;
  48. else{
  49.  
  50. for (int i=0; i<3; i++)
  51. {d=name.compare(arr[i][50]);
  52.     if (d==0)
  53. j++;}
  54. if (j>0)
  55. cout<<"File found."<<endl;
  56. }}
  57. void tofile(fstream &write);
  58.  
  59. string Str2str(String ^a)
  60. {
  61. array<Byte> ^chars = System::Text::Encoding::ASCII->GetBytes(a);
  62. pin_ptr<Byte> charsPointer = &(chars[0]);
  63. char *nativeCharsPointer = reinterpret_cast<char *>(static_cast<unsigned char *>(charsPointer));
  64. string native(nativeCharsPointer, chars->Length);
  65. return native;
  66. }
  67.  
  68. int menu()
  69. {int i;
  70. cout<<"SELECT FROM THE FOLLOWING:\n"<<endl<<"1-- TO INDEX D:\\ "<<endl<<"2-- TO SEARCH A FILE BY ITS NAME"<<endl<<"3--TO SEARCH A WORD IN TEXT FILES"<<endl<<"4--TO EXIT"<<endl<<"ENTER YOUR CHOICE"<<endl;
  71. cin>>i;
  72. return i;}
  73.  
  74. int main()
  75. {
  76. system("cls");
  77.  
  78. Loging_Project l1;    
  79.  
  80.  
  81. fstream names;
  82. l1.Info("Displaying the menu");
  83. while(1)
  84. {system("cls");
  85.     int i=menu();
  86. l1.Info("user entered a choice");
  87. switch(i)
  88. {case 1:
  89.         { 
  90.             l1.Info("Calling function which creates an indexed file");
  91.         tofile(names);
  92.         system("pause");
  93.  
  94.         }
  95.  
  96.             break;
  97.  
  98. case 2:
  99.     {
  100.     l1.Info("user asked to search a file ");
  101.         search();
  102.     }
  103. break;
  104.  
  105. case 3:
  106.     {
  107.         l1.Info("user asked to search a word ");
  108.     int cnt;
  109.     string wordtofind;
  110.     wordtofind=input();
  111.     string temp;
  112.     fstream file;
  113.     file.open("D:\\myfile.txt",ios::in);
  114.  
  115. while( file.good() )
  116.  
  117. {
  118.     file>>temp;
  119.     cnt=count(temp,wordtofind);
  120.     cout<<"the entered word '"<<wordtofind<<"' occured "<<cnt<<" times in file "<<temp<<endl;
  121.  
  122.        }
  123.  
  124.  
  125. case 4:
  126.     {l1.Info("exting");
  127.     exit(0);}
  128. default: cout<<"ENTER A VALID CHOICE";
  129.  
  130. }//end switch
  131. }
  132. l1.Info("exting");
  133. }//main ends
  134.  
  135.  
  136. //function to write the data on file
  137. void tofile(fstream &write)
  138. {
  139.     system("cls");
  140.     directory d;
  141.     d.searchd();
  142.     d.searchf();
  143.     write.open("d:\\myfile.txt",ios::out);
  144.     if(!write)
  145.     {cerr<<"FILE COULD NOT BE OPENED"<<endl;
  146.     exit(1);
  147. }//
  148.  
  149.     cout<<"INDEXING IN PROGRESS....";
  150.     write<<"\nLIST OF SUB DIRECTORIES:"<<endl;
  151.     for(int di=0;di<d.getsized();di++)
  152.     write<<d.getname(di)<<endl;
  153.     write<<"\n\n\nLIST OF FILES:"<<endl;
  154.     for(int q=0;q<d.getsizef();q++)
  155.     write<<d.getfname(q)<<"  "<<d.getfbytes(q)<<endl;
  156.     system("cls");
  157.     cout<<"----------INDEXING DONE----------"<<endl;
  158.  
  159. }
Apr 8 '11 #1
1 2614
weaknessforcats
9,208 Expert Mod 8TB
You are missing a closing } for case 3. That puts case 4 inside case 3 and if you go to case 4 you miss the initialization in case 3.
Apr 9 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Neil Zanella | last post by:
Hello, Does anyone know what the following g++ compiler error message means: error: jump to case label I get this error when switching two case labels together with their bodies. I have no...
8
by: JKop | last post by:
g++ test.cpp -ansi -pedantic -o test.exe test.cpp: In function `int main()': test.cpp:22: case label does not reduce to an integer constant Why won't "operator unsigned int() const" do its job...
29
by: SysSpider | last post by:
Hi again, This is my problem: when i try to compile the code that contains the function below, i get this: -- gcc:21: error: case label does not reduce to an integer constant gcc:24: error:...
14
by: subramanian100in | last post by:
Consider the following program: #include <iostream> using namespace std; int main() { int i;
3
by: newguy194 | last post by:
I am currently writing a Win32 application and when I compile I get a "Jump to case label" error and another error tellling me that switch(LOWORD(wParam)) is unreachable in the switch, when I remove...
4
by: clairelee0322 | last post by:
My program has an error C2360: initialization of 'i' is skipped by 'case' label. I don't know why. Please help me out! thks!! the error occurs in Division case 3. //Claire's Calculator...
5
by: Rex Mottram | last post by:
Can anyone explain this? % cat t.c #include <stdio.h> #define FIRST "first" #define SECOND "second" int main(int argc, char *argv)
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.