GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Placement Papers  >  MindTree  >  Technical
Next Question 
 Technical  |  Question 1 of 6    Print  
We have to count the 3 letter,4letter and 5letter words from a file and print the number of 3 letter,4letter and 5letter words. Delimiter is space,tab,hifen.Also we should not consider the line in the file after we encounter # in that line.(ie after # we should not consider the portion of line)

  
Total Answers and Comments: 7 Last Update: July 18, 2008   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
July 10, 2005 05:41:15   #1  
alok        

RE: We have to count the 3 letter,4letter and 5letter words from a file and print the number of 3 letter...
hii
Any one can post the answer of this question.
plzz
bye

 
Is this answer useful? Yes | No
July 21, 2005 09:01:10   #2  
ajeet        

RE: We have to count the 3 letter,4letter and 5letter words from a file and print the number of 3 letter...
hi
use fscanf(....) to read the string calculate length using strlen function and increment the counter for respective words.
we will have to take care of #.

 
Is this answer useful? Yes | No
August 02, 2005 02:55:10   #3  
Padiyar        

RE: We have to count the 3 letter,4letter and 5letter words from a file and print the number of 3 letter...
For # we can use the String.indexOf( # ) method to check the # substring
 
Is this answer useful? Yes | No
October 14, 2005 05:09:27   #4  
Rajaram        

Find out Count of Words which has 3Letters or 2Letters or 4Letters or 5Letters and splited the string by (,: \t)

There are two ways to do this program. Both the ways are shown below.

1)

using System;

using System.IO;

namespace nmsFileOperations

{

class clzFileOperations

{

[STAThread]

static void Main(string[] args)

{

string strLine;

int Wrd1 0 Wrd2 0 Wrd3 0;

int Wrd4 0 Wrd5 0 Wrd6 0;

StreamReader sr new StreamReader(@ c:\a.txt );

strLine sr.ReadLine();

while(strLine! null)

{

if (strLine.Trim().Substring(0 1)! # )

{

string [] strSplit strLine.Trim().Split(new char[] {' ' '.' ';' ':' '\t'});

foreach(string str in strSplit)

{

switch(str.Length)

{

case 1:

Wrd1++;

break;

case 2:

Wrd2++;

break;

case 3:

Wrd3++;

break;

case 4:

Wrd4++;

break;

case 5:

Wrd5++;

break;

case 6:

Wrd6++;

break;

}

}

}

strLine sr.ReadLine();

}

Console.WriteLine( The Count of One Letters Word is {0} + Wrd1);

Console.WriteLine( The Count of Two Letters Word is {0} + Wrd2);

Console.WriteLine( The Count of Three Letters Word is {0} + Wrd3);

Console.WriteLine( The Count of Four Letters Word is {0} + Wrd4);

Console.WriteLine( The Count of Five Letters Word is {0} + Wrd5);

Console.WriteLine( The Count of Six Letters Word is {0} + Wrd6);

}

}

}

2)

using System;

using System.IO;

namespace nmsFileHandling

{

class clzFileHandling

{

[STAThread]

static void Main(string[] args)

{

string strLine;

string [] strWord;

int Wrd1 0 Wrd2 0 Wrd3 0 Wrd4 0;

int Wrd5 0 Wrd6 0;

StreamReader sr new StreamReader(@ c:\a.txt );

strLine sr.ReadLine().Trim();

while (strLine! null)

{

if (strLine.Trim().Substring(0 1)! # )

{

//strWord strLine.Split(' ');

strWord strLine.Split(new char[] {' ' '.' ';' ':' '\t'});

for (int i 0; i< strWord.Length-1; i++)

{

switch (strWord[i].Trim().Length)

{

case 1:

Wrd1++;

break;

case 2:

Wrd2++;

break;

case 3:

Wrd3++;

break;

case 4:

Wrd4++;

break;

case 5:

Wrd5++;

break;

case 6:

Wrd6++;

break;

}

}

}

strLine sr.ReadLine();

}

Console.WriteLine( \nTotol Number of One word Letters is {0} Wrd1);

Console.WriteLine( \nTotol Number of Two word Letters is {0} Wrd2);

Console.WriteLine( \nTotol Number of Three word Letters is {0} Wrd3);

Console.WriteLine( \nTotol Number of Four word Letters is {0} Wrd4);

Console.WriteLine( \nTotol Number of Five word Letters is {0} Wrd5);

Console.WriteLine( \nTotol Number of Six word Letters is {0} Wrd6);

}

}

}


 
Is this answer useful? Yes | No
October 14, 2005 06:19:10   #5  
Rajaram Member Since: October 2005   Contribution: 1    

RE: We have to count the 3 letter,4letter and 5letter ...

Write a program to Open a file and read each and every line which doesn't start from # symbol and display the following details

Count the Number of words which has

1Letters of word

2Letters of word

3Letters of word

4Letters of word

And Each word splited by : \t .

1)

using System;

using System.IO;

namespace nmsFileOperations

{

class clzFileOperations

{

[STAThread]

static void Main(string[] args)

{

string strLine;

int Wrd1 0 Wrd2 0 Wrd3 0;

int Wrd4 0 Wrd5 0 Wrd6 0;

StreamReader sr new StreamReader(@ c:\a.txt );

strLine sr.ReadLine();

while(strLine! null)

{

if (strLine.Trim().Substring(0 1)! # )

{

string [] strSplit strLine.Trim().Split(new char[] {' ' '.' ';' ':' '\t'});

foreach(string str in strSplit)

{

switch(str.Length)

{

case 1:

Wrd1++;

break;

case 2:

Wrd2++;

break;

case 3:

Wrd3++;

break;

case 4:

Wrd4++;

break;

case 5:

Wrd5++;

break;

case 6:

Wrd6++;

break;

}

}

}

strLine sr.ReadLine();

}

Console.WriteLine( The Count of One Letters Word is {0} + Wrd1);

Console.WriteLine( The Count of Two Letters Word is {0} + Wrd2);

Console.WriteLine( The Count of Three Letters Word is {0} + Wrd3);

Console.WriteLine( The Count of Four Letters Word is {0} + Wrd4);

Console.WriteLine( The Count of Five Letters Word is {0} + Wrd5);

Console.WriteLine( The Count of Six Letters Word is {0} + Wrd6);

}

}

}


 
Is this answer useful? Yes | No
March 04, 2006 14:43:12   #6  
Amit Rathi        

RE: We have to count the 3 letter,4letter and 5letter ...
Dim str As StringDim sr As New System.IO.StreamReader( c:/temp.txt ) str sr.ReadToEnd Dim ar() As String str.Split( ) For i As Integer 0 To ar.Length - 1 If (ar(i).Length 3) Then MsgBox(ar(i)) End If Next
 
Is this answer useful? Yes | No
July 18, 2008 15:21:34   #7  
paul.anuj Member Since: February 2008   Contribution: 5    

RE: We have to count the 3 letter,4letter and 5letter words from a file and print the number of 3 letter,4letter and 5letter words. Delimiter is space,tab,hifen.Also we should not consider the line in the file after we encounter # in that line.(ie after #
dont know
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape