home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2698
Discussions: 188,384, Posts: 2,243,498, Members: 232,613
Old November 22nd, 2002, 06:28 AM   Digg it!   #1 (permalink)
Banned
 
Join Date: Nov 2002
Posts: 6
Send a message via AIM to Krusho Send a message via Yahoo to Krusho
Two Dimensional Array

Code:
#include <stdio.h>

/* This function compares the strings */
int StrCmp(char *s, char *t, int length)
{
	/* Initializes i */
	int i;

	/* For loop that only returns value if s[i] is null */
	for(i = 0; i < length; i++)
		if(s[i] != t[1])
			return -1;

	return 0;
}

/* This function takes all the characters and makes them UPPERCASE */
int LowUpp(int ch)
{
	if ('a' <= ch && ch <= 'z')
	{
		return (ch + 'A' - 'a');
	}
	else
	{
		return ch;
	}
}

char c; /* Initializes c */

int main()
{
	
	int LowUpp(int ch);

	/* The following delcares the variables to be used in the program */
	char word[23];
	char userstring[1024];
	char Array[1024][100];
	int wordcount = 0;
	int charcount = 0;
	int wordnumb = 0;
	int i = 0;
	int j = 0;
	int row = 0;
	int column = 0;

	/* Next the Title and Enter your input are printed to the screen */
	printf("Word & Character Counter\n\n\n");
	printf("Enter your input ([CTRL+Z] To Quit): ");

	/* This if statement takes in the string from the user */
	if(fgets(userstring, 1024, stdin) == NULL)
		return 0;

	/* This prints the main parts of the table */
	printf("\n\nWord Count		");
	printf("Word			");
	printf("Character Count	\n");
	printf("---------------------------------------------------------------\n");

	/* This while loop continues as long as the userstring[i] is not null */
	while(userstring[i] != '\0')
	{ 
		/* If the userstring is equal to a space AND return AND tab */
		if((userstring[i] != ' ') && (userstring[i] != '\n') && (userstring[i] != '\t'))
		{ 
			/* Increments charcount */
			charcount++;

			/* Uses the LowUpp function on the input whichs turns in into uppercase */
			word[j++] = LowUpp(userstring[i]);
		}
		else
		{
			/* Increments wordnumb */
			wordnumb++;

			word[j] = '\0';

			/* Saves it to the array */
			Array[row][column] = word[i];

			/* If charcount is less than 8 */
			if(charcount < 8)
				/* Prints the input to the screen */
				printf("%d\t\t\t%s\t\t\t%d\n", wordnumb, word, charcount);
			else
				/* Prints the input to the screen */
				printf("%d\t\t\t%s\t%d\n", wordnumb, word, charcount);

			/* Sets charcount to 0 */
			charcount = 0;

			/* Increments wordcount  */
			wordcount++;

			/* Sets j equal to 0 */
			j = 0;
		}
		
		/* Increments i */
		i++;
	}
	
	/* Prints the end of the table to the screen */
	printf("---------------------------------------------------------------\n");
	printf("Total Words:  %d\n\n", wordcount);
	
	/* Returns 0 */
	return 0;
}
How can I put this into a two dimensional array? Also how would I check so it doesn't output the same word twice?

Krusho is offline   Reply With Quote
Old November 22nd, 2002, 08:53 AM     #2 (permalink)
Senior Member
 
RustyGT's Avatar
 
Join Date: Oct 2001
Location: NQ. Aust.
Posts: 897
Beats me, bloke...

RustyGT is offline   Reply With Quote
Old November 22nd, 2002, 12:41 PM     #3 (permalink)
Ultimate Member
 
ironforge's Avatar
 
Join Date: Oct 2001
Posts: 1,109
Send a message via ICQ to ironforge
a wordcount program? I have done a similar project a couple of years ago..

it goes through an arbitrary text file and tells you how many times each word occurs.. as well as a final count..

output looks like this:

APPLE - 23
BEACON - 2
ZENITH - 5

TOTAL COUNT = 30

(of course you don't have to have it in caps, just for emphasis)

something like that... if it encounters a word more than once.. it just increments the counter each time... now of course you could take this out easily..

the code is on my home PC though.. hhehe.. also it is C++ code..

I think what I did was just create a two dimensional array.. and when you read in a word.. do a binary search on that array to see if the word is already there.. and if so increment it's count.. if not.. then insert it into the array (in order of course)

ironforge is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2896)
The United States Debt (20)
3-days in and no threads about Gaza (160)
I think I just killed my computer w.. (24)
Upgrading RAM (5)
hp compaq nc6000 problems (138)
Folderchat Weekday thread (441)
Antec 300 bulk purchase? (11)
Worth the upgrade?? (15)
Recent Discussions
ACPI controller halt on boot (2)
Building a gaming computer advi.. (3)
Worth the upgrade?? (15)
Folderchat Weekday thread (441)
ADVICE (0)
How to increase my ram? (5)
Help with an Ati Radeon HD 4850.. (27)
CPU wont boot (4)
2nd video card (1)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 09:54 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28