473,395 Members | 1,541 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,395 software developers and data experts.

C# programming

4
I am getting an error when I try to run the MyKwic . I entered MyKwic practiceFile(which i saved in the project). However, the compiler does not seem to trace the practiceFile. Here is MyKwic:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6.  
  7. public class Mykwic
  8. {
  9.     static void Main(string[] args)
  10.     {
  11.         if (args.Length == 0)
  12.         {
  13.             Console.WriteLine("Error: Missing file name");
  14.             return;
  15.         }
  16.  
  17.         StreamReader reader = null;
  18.         Hashtable table = new Hashtable();
  19.  
  20.         try
  21.         {
  22.             reader = new StreamReader(args[0]);
  23.  
  24.             for (string line = reader.ReadLine(); line != null; line = reader.ReadLine())
  25.             {
  26.                 string[] words = GetWords(line);
  27.  
  28.                 foreach (string word in words)
  29.                 {
  30.                     string iword = word.ToLower();
  31.                     if (table.ContainsKey(iword))
  32.                         table[iword] = (int)table[iword] + 1;
  33.                     else
  34.                         table[iword] = 1;
  35.                 }
  36.  
  37.             }
  38.             SortedList list = new SortedList(table);
  39.  
  40.             Console.WriteLine("{0} unique words found in {1}", table.Count, args[0]);
  41.  
  42.             foreach (DictionaryEntry entry in list)
  43.                 Console.WriteLine("{0} ({1})", entry.Key, entry.Value);
  44.         }
  45.         catch (Exception e)
  46.         {
  47.             Console.WriteLine(e.Message);
  48.         }
  49.         finally
  50.         {
  51.             if (reader != null)
  52.                 reader.Close();
  53.         }
  54.     }
  55.  
  56.     static string[] GetWords(string line)
  57.     {
  58.         ArrayList al = new ArrayList();
  59.  
  60.         int i = 0;
  61.         string word;
  62.         char[] characters = line.ToCharArray();
  63.  
  64.         while ((word = GetNextWord(line, characters, ref i)) != null)
  65.             al.Add(word);
  66.  
  67.         string[] words = new string[al.Count];
  68.         al.CopyTo(words);
  69.         return words;
  70.     }
  71.  
  72.     static string GetNextWord(string line, char[] characters, ref int i)
  73.     {
  74.         while (i < characters.Length && !Char.IsLetterOrDigit(characters[i]))
  75.             i++;
  76.         if (i == characters.Length)
  77.             return null;
  78.  
  79.         int start = i;
  80.  
  81.         while (i < characters.Length && Char.IsLetterOrDigit(characters[i]))
  82.             i++;
  83.         return line.Substring(start, i - start);
  84.     }
  85.  
  86. }
  87.  
Feb 12 '08 #1
1 745
Plater
7,872 Expert 4TB
What do you mean by "trace"?
Feb 12 '08 #2

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

Similar topics

5
by: Martin | last post by:
When was inheritance intruduced into object oriented programming? More generally, does anyone know or have any sources on when the different features were introduced into object oriented...
12
by: G. | last post by:
Hi all, During my degree, BEng (Hons) Electronics and Communications Engineering, we did C programming every year, but I never kept it up, as I had no interest and didn't see the point. But now...
3
by: user | last post by:
Hi all, At the outset, I regret having to post this slightly OT post here. However, I strongly feel that people in this group would be the best to advise me on my predicament. I am working as...
134
by: evolnet.regular | last post by:
I've been utilising C for lots of small and a few medium-sized personal projects over the course of the past decade, and I've realised lately just how little progress it's made since then. I've...
7
by: Robert Seacord | last post by:
The CERT/CC has just deployed a new web site dedicated to developing secure coding standards for the C programming language, C++, and eventually other programming language. We have already...
30
by: Jakle | last post by:
I have been googling, but can seem to find out about C GUI libraries. My main platform is Windows, but it would be nice to find a cross platform library. I've been programming with php, which...
47
by: Thierry Chappuis | last post by:
Hi, I'm interested in techniques used to program in an object-oriented way using the C ANSI language. I'm studying the GObject library and Laurent Deniau's OOPC framework published on his web...
111
by: Enteng | last post by:
Hi I'm thinking about learning C as my first programming language. Would you recommend it? Also how do you suggest that I learn it?What books/tutorials should I read for someone like me? Thanks...
14
by: deko | last post by:
For building Windows desktop apps, the clear favorite is C#. But my clients can't afford to buy Microsoft products. So I need to develop software for Linux users and web applications. In the...
17
by: CoreyWhite | last post by:
I bought this book years ago, when I was just learning C++. Since then I've gone through every math course offered at my college, taken courses on coding C & thinking in terms how how to make the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.