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: 2746
Discussions: 188,385, Posts: 2,243,517, Members: 232,615
Old November 22nd, 2002, 06:30 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 the input into a two dimensional array? And make it only output each occurence of the same word only once.

Krusho is offline   Reply With Quote
Old November 22nd, 2002, 06:44 AM     #2 (permalink)
Ultimate Member
 
strangerstill's Avatar
 
Join Date: Oct 2001
Posts: 1,542
1. Iterate over two variables [i][j]
2. Hmm... some sort of associative array would seem to be indicated. As it's an unsorted usage, some type of hash table char * => int say could be the best (most efficient) way of doing it, however just a straight sorted array char *[] and int[] would be fairly easy to implement - use binary search to find the key index or insertion point, then ++int[i] or extend the arrays and insert the key-value pair (key being char *keyword, value being count := 1 at insertion) Alternatively a struct { char *; int } [] array might work quite well.

strangerstill is offline   Reply With Quote
Old November 22nd, 2002, 06:54 AM     #3 (permalink)
Banned
 
Join Date: Nov 2002
Posts: 6
Send a message via AIM to Krusho Send a message via Yahoo to Krusho
Could you show me? I know the idea of what needs done I just can't picture exactly how to do it.

Krusho 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? (2899)
CPU wont boot (7)
3-days in and no threads about Gaza (160)
I think I just killed my computer w.. (24)
hp compaq nc6000 problems (139)
Upgrading RAM (5)
Folderchat Weekday thread (442)
Antec 300 bulk purchase? (11)
Worth the upgrade?? (15)
Recent Discussions
New Build ( Finally ) (3)
CPU wont boot (7)
Problem With LightScribe DVD Dr.. (0)
GLaDOS is up. (3)
HP notebook reinstall Vista NO .. (5)
Building a gaming computer advi.. (4)
hp compaq nc6000 problems (139)
Folderchat Weekday thread (442)
Creative T-3000 Subwoofer (3)
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 11:10 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