Forum Settings
Forums
New
This topic has been locked and is no longer available for discussion.
Pages (200) « First ... « 119 120 [121] 122 123 » ... Last »
Oct 10, 2009 3:05 AM

Offline
Apr 2008
8333

Oct 10, 2009 3:06 AM

Offline
Sep 2009
368
Saitoe said:
#include "cvector.h"
#include "cmap.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void PrintCVector(CVector*v);
int StrPtrCompare(const void *ptr1, const void *ptr2);
int AllAlpha(char*a);
int IntPtrCompare(const void *ptr1, const void *ptr2);

int main(int argc, const char *argv[])
{
printf("Assignment 2 has begun!n");
CVector *stopWord = CVectorAlloc(100*sizeof(char*),400,NULL);
CVector *inputWord = CVectorAlloc(100*sizeof(char*),600,NULL);
CVector *key = CVectorAlloc(100*sizeof(char*),300,NULL);
CMap *tagCloud = CMapAlloc(sizeof(int),300,NULL);
CVector *topIndex = CVectorAlloc(sizeof(int),50,NULL);
CVector *topKey = CVectorAlloc(100*sizeof(char*),50,NULL);

char*buffer_ptr;
int stopBool=0;
//This flips the bool flag if there is no 2nd argument
FILE *fp = fopen(argv[2], "r");
if (fp == NULL) stopBool=1;
else
{
while (!feof(fp))
{
/*Reads stopword file line by line into buffer, then appends to
the vector*/
buffer_ptr=(char*)malloc(1000*sizeof(char*));
fscanf(fp,"%s",buffer_ptr);
CVectorAppend(stopWord,&buffer_ptr);
}
CVectorSort(stopWord,StrPtrCompare);
fclose(fp);
}

//Reads in the input into the inputWord vector
FILE *fp1 = fopen(argv[1],"r");
if(fp1==NULL) return 1;
while(!feof(fp1))
{
buffer_ptr=(char*)malloc(1000*sizeof(char*));
fscanf(fp1,"%s",buffer_ptr);
CVectorAppend(inputWord,&buffer_ptr);
}
fclose(fp1);

/*This subroutine loops over all of the words obtained in from the
input and checks them against the conditions established in the
assignment. An element will only be added if all of the characters are
alphabetical and if the element is > 3 in length. If the element
satisfies these two conditions, the element is checked to make sure
that it is not a stopword, if there are stopwords. Finally, it is
checked to ensure that the element has not already been added. If it
hasn't, then the element will be added to the tagCloud CMap, and if it
is already present, then the value at that key will be extracted and incremented.
*/
int i;
int*val;
for(i=0;i<CVectorCount(inputWord);i++)
{
char*element = *(char**)CVectorNth(inputWord,i);
if(strlen(element)>3&&AllAlpha(element)==1)
{
if(stopBool==1||CVectorSearch(stopWord,&element,StrPtrCompare,0,1)==-1)
{
if(CMapGet(tagCloud,element)==NULL)
{
val=(int*)malloc(sizeof(int));
*val=1;
CMapPut(tagCloud,element,val);
CVectorAppend(key,&element);
}
else
{
val=CMapGet(tagCloud,element);
*val=*val+1;
}
}
}
}

/*Only loops 50 times, or the length of key, whichever is less. This
subroutine determines the indecies of the 50 elements with the highest
frequency. It loops over key, checking to make sure the index being
checked isn't already in the topIndex CVector. Then, it uses
intermediate variables max and maxIndex to keep track of the current
maxima for each iteration, and stores them in topIndex once the inner
loop finishes iterating. Note: the if statements and the variable
assignments above both of them could be condensed to one line, but I
left it as is so as to not reduce readability
*/
int max =0;
int maxIndex=0;
i=0;
while(i<50 && i<CVectorCount(key))
{
max=0;
maxIndex=0;
CVectorSort(topIndex, IntPtrCompare);
int j;
for(j=0;j<CVectorCount(key);j++)
{
int x=CVectorSearch(topIndex,&j,IntPtrCompare,0,1);
if(x==-1)
{
int y = *(int*)CMapGet(tagCloud,*(char**)CVectorNth(key,j));
if(y>max)
{
max=y;
maxIndex=j;
}
}
}

CVectorAppend(topIndex,&maxIndex);
i++;
}

/*Fills in the topKey by simply iterating through topIndex. This is
necessary to produce a sorted result*/
for(i=0;i<CVectorCount(topIndex);i++)
{
char*element=*(char**)CVectorNth(key,*(int*)CVectorNth(topIndex,i));
CVectorAppend(topKey,&element);
}

//Sort the list of keys and then print according to desired output format
CVectorSort(topKey,StrPtrCompare);
for(i=0;i<CVectorCount(topKey);i++)
{
printf("%st%dn",*(char**)CVectorNth(topKey,i),*(int*)CMapGet(tagCloud,*(char**)CVectorNth(topKey,i)));
}

//Free up memory
CVectorFree(inputWord);
CVectorFree(stopWord);
CVectorFree(key);
CVectorFree(topIndex);
CVectorFree(topKey);
CMapFree(tagCloud);
return 0;
}

//Comparison of 2 integers, as given in Lab2
int IntPtrCompare(const void *ptr1, const void *ptr2)
{
return *(int *)ptr1-*(int *)ptr2;
}

//Comparison of 2 strings, as derived in Lab2
int StrPtrCompare(const void *ptr1, const void *ptr2)
{
return strcmp(*(char**)ptr1,*(char**)ptr2);
}

//Function to print CVector V that stores char*. Used for testing
void PrintCVector(CVector*v)
{
int i;
for(i=0;i<CVectorCount(v);i++)
{
printf("%sn",*(char**)CVectorNth(v,i));
}
}

//Returns 1 if all elements are alphabetical characters
//Returns 0 otherwise
int AllAlpha(char*a)
{
int i;
for(i=0;i<strlen(a);i++)
if((int)a<65 || (int)a>122)
return 0;
return 1;
}
Saitoe said:
#include "cvector.h"
#include "cmap.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void PrintCVector(CVector*v);
int StrPtrCompare(const void *ptr1, const void *ptr2);
int AllAlpha(char*a);
int IntPtrCompare(const void *ptr1, const void *ptr2);

int main(int argc, const char *argv[])
{
printf("Assignment 2 has begun!n");
CVector *stopWord = CVectorAlloc(100*sizeof(char*),400,NULL);
CVector *inputWord = CVectorAlloc(100*sizeof(char*),600,NULL);
CVector *key = CVectorAlloc(100*sizeof(char*),300,NULL);
CMap *tagCloud = CMapAlloc(sizeof(int),300,NULL);
CVector *topIndex = CVectorAlloc(sizeof(int),50,NULL);
CVector *topKey = CVectorAlloc(100*sizeof(char*),50,NULL);

char*buffer_ptr;
int stopBool=0;
//This flips the bool flag if there is no 2nd argument
FILE *fp = fopen(argv[2], "r");
if (fp == NULL) stopBool=1;
else
{
while (!feof(fp))
{
/*Reads stopword file line by line into buffer, then appends to
the vector*/
buffer_ptr=(char*)malloc(1000*sizeof(char*));
fscanf(fp,"%s",buffer_ptr);
CVectorAppend(stopWord,&buffer_ptr);
}
CVectorSort(stopWord,StrPtrCompare);
fclose(fp);
}

//Reads in the input into the inputWord vector
FILE *fp1 = fopen(argv[1],"r");
if(fp1==NULL) return 1;
while(!feof(fp1))
{
buffer_ptr=(char*)malloc(1000*sizeof(char*));
fscanf(fp1,"%s",buffer_ptr);
CVectorAppend(inputWord,&buffer_ptr);
}
fclose(fp1);

/*This subroutine loops over all of the words obtained in from the
input and checks them against the conditions established in the
assignment. An element will only be added if all of the characters are
alphabetical and if the element is > 3 in length. If the element
satisfies these two conditions, the element is checked to make sure
that it is not a stopword, if there are stopwords. Finally, it is
checked to ensure that the element has not already been added. If it
hasn't, then the element will be added to the tagCloud CMap, and if it
is already present, then the value at that key will be extracted and incremented.
*/
int i;
int*val;
for(i=0;i<CVectorCount(inputWord);i++)
{
char*element = *(char**)CVectorNth(inputWord,i);
if(strlen(element)>3&&AllAlpha(element)==1)
{
if(stopBool==1||CVectorSearch(stopWord,&element,StrPtrCompare,0,1)==-1)
{
if(CMapGet(tagCloud,element)==NULL)
{
val=(int*)malloc(sizeof(int));
*val=1;
CMapPut(tagCloud,element,val);
CVectorAppend(key,&element);
}
else
{
val=CMapGet(tagCloud,element);
*val=*val+1;
}
}
}
}

/*Only loops 50 times, or the length of key, whichever is less. This
subroutine determines the indecies of the 50 elements with the highest
frequency. It loops over key, checking to make sure the index being
checked isn't already in the topIndex CVector. Then, it uses
intermediate variables max and maxIndex to keep track of the current
maxima for each iteration, and stores them in topIndex once the inner
loop finishes iterating. Note: the if statements and the variable
assignments above both of them could be condensed to one line, but I
left it as is so as to not reduce readability
*/
int max =0;
int maxIndex=0;
i=0;
while(i<50 && i<CVectorCount(key))
{
max=0;
maxIndex=0;
CVectorSort(topIndex, IntPtrCompare);
int j;
for(j=0;j<CVectorCount(key);j++)
{
int x=CVectorSearch(topIndex,&j,IntPtrCompare,0,1);
if(x==-1)
{
int y = *(int*)CMapGet(tagCloud,*(char**)CVectorNth(key,j));
if(y>max)
{
max=y;
maxIndex=j;
}
}
}

CVectorAppend(topIndex,&maxIndex);
i++;
}

/*Fills in the topKey by simply iterating through topIndex. This is
necessary to produce a sorted result*/
for(i=0;i<CVectorCount(topIndex);i++)
{
char*element=*(char**)CVectorNth(key,*(int*)CVectorNth(topIndex,i));
CVectorAppend(topKey,&element);
}

//Sort the list of keys and then print according to desired output format
CVectorSort(topKey,StrPtrCompare);
for(i=0;i<CVectorCount(topKey);i++)
{
printf("%st%dn",*(char**)CVectorNth(topKey,i),*(int*)CMapGet(tagCloud,*(char**)CVectorNth(topKey,i)));
}

//Free up memory
CVectorFree(inputWord);
CVectorFree(stopWord);
CVectorFree(key);
CVectorFree(topIndex);
CVectorFree(topKey);
CMapFree(tagCloud);
return 0;
}

//Comparison of 2 integers, as given in Lab2
int IntPtrCompare(const void *ptr1, const void *ptr2)
{
return *(int *)ptr1-*(int *)ptr2;
}

//Comparison of 2 strings, as derived in Lab2
int StrPtrCompare(const void *ptr1, const void *ptr2)
{
return strcmp(*(char**)ptr1,*(char**)ptr2);
}

//Function to print CVector V that stores char*. Used for testing
void PrintCVector(CVector*v)
{
int i;
for(i=0;i<CVectorCount(v);i++)
{
printf("%sn",*(char**)CVectorNth(v,i));
}
}

//Returns 1 if all elements are alphabetical characters
//Returns 0 otherwise
int AllAlpha(char*a)
{
int i;
for(i=0;i<strlen(a);i++)
if((int)a<65 || (int)a>122)
return 0;
return 1;
}
Oct 10, 2009 4:31 AM

Offline
Feb 2008
5396
YEAH, GOOD MORNING TO YOU TOO GSTS. YOU WHORES.
Oct 10, 2009 4:39 AM
Offline
Oct 2007
1412
yeah.
Oct 10, 2009 4:44 AM

Offline
Feb 2008
5396
forlacik said:
yeah.
Hey bro.
Oct 10, 2009 4:49 AM
Offline
Oct 2007
1412
LolitaDecay said:
forlacik said:
yeah.
Hey bro.
Hi dudette.
Oct 10, 2009 4:53 AM

Offline
Feb 2008
5396
forlacik said:
LolitaDecay said:
forlacik said:
yeah.
Hey bro.
Hi dudette.
How you doin'?
Oct 10, 2009 4:56 AM

Offline
Feb 2008
5396
brb, need to do my hair
Oct 10, 2009 4:57 AM
Offline
Oct 2007
1412
LolitaDecay said:
forlacik said:
LolitaDecay said:
forlacik said:
yeah.
Hey bro.
Hi dudette.
How you doin'?
Tired, I slept too long! And hungry. So not much.
Oct 10, 2009 4:58 AM

Offline
Feb 2008
5396
forlacik said:
LolitaDecay said:
forlacik said:
LolitaDecay said:
forlacik said:
yeah.
Hey bro.
Hi dudette.
How you doin'?
Tired, I slept too long! And hungry. So not much.
I slept for like 12 hours. I was mega tired.
Oct 10, 2009 5:02 AM

Offline
Jul 2008
1374
I always sleep for 12 hours.
Oct 10, 2009 5:06 AM

Offline
Jul 2008
1374
Then I feel like shit for the next 12 hours.
Oct 10, 2009 5:16 AM
Offline
Nov 2007
2010
DDDDDDDDDD:
Oct 10, 2009 5:17 AM

Offline
Feb 2008
5396
AMAYA AND EDDIE.
Oct 10, 2009 5:18 AM

Offline
Aug 2008
1103
Hiiii Amayayayayayyayayayayayaaaaaaaaa~
Oct 10, 2009 5:18 AM

Offline
Aug 2008
1103
LolitaDecay said:
AMAYA AND EDDIE.
AND MEEE :D
Oct 10, 2009 5:18 AM

Offline
Dec 2008
928
":D
Oct 10, 2009 5:19 AM

Offline
Aug 2008
1103
Avarance said:
":D
Ello you :B
Oct 10, 2009 5:19 AM

Offline
Jul 2008
1374
Enjoy life as a pro
while we is suckin on dat dro
you don't kno
Oct 10, 2009 5:21 AM

Offline
Aug 2008
1103
EddieSpaghetti said:
Enjoy life as a pro
while we is suckin on dat dro
you don't kno
You could have killed me before I came to work today love. Atleast could have put me in hospitallll D:

the wankers are out todaay : <
Oct 10, 2009 5:22 AM
Offline
Nov 2007
2010
LolitaDecay said:
AMAYA AND EDDIE.
LOLIIIIII~ <3

Kirky said:
Hiiii Amayayayayayyayayayayayaaaaaaaaa~
KIRKYYYY~ <3

Avarance said:
":D
AVAAAAAAA~ <3

EddieSpaghetti said:
I always sleep for 12 hours.
EDDIEEEEEE~ <3

We have 5 people. If we die now, I'll kill myself.
Oct 10, 2009 5:22 AM

Offline
Aug 2008
1103
Well, they're out everyday.

But. Today, they're especially wanky.
Oct 10, 2009 5:23 AM

Offline
Feb 2008
5396
HELLO ALL OF YOU.
I love you all.

But I really need a sammich.
Oct 10, 2009 5:23 AM

Offline
Aug 2008
1103
Amaya-no-Hime said:
KIRKYYYY~ <3
Elloo gurrl~ Ya alrite?

Please don't kill yourself D:

:B
Oct 10, 2009 5:23 AM

Offline
Aug 2008
1103
LolitaDecay said:
HELLO ALL OF YOU.
I love you all.

But I really need a sammich.
You wench. :B
Oct 10, 2009 5:25 AM
Offline
Nov 2007
2010
LolitaDecay said:
HELLO ALL OF YOU.
I love you all.

But I really need a sammich.
Get me one too, love~

Kirky said:
Amaya-no-Hime said:
KIRKYYYY~ <3
Elloo gurrl~ Ya alrite?

Please don't kill yourself D:

:B
I'm good, I'm good.

Rofl, I refuse to kill myself until DtB season 2 finishes.
Oct 10, 2009 5:26 AM

Offline
Jul 2008
1374
Kirky said:
EddieSpaghetti said:
Enjoy life as a pro
while we is suckin on dat dro
you don't kno
You could have killed me before I came to work today love. Atleast could have put me in hospitallll D:

the wankers are out todaay : <
Now, why would I want to kill you?


Amaya-no-Hime said:

EddieSpaghetti said:
I always sleep for 12 hours.
EDDIEEEEEE~ <3

We have 5 people. If we die now, I'll kill myself.
Ello.
Oct 10, 2009 5:26 AM

Offline
Aug 2008
1103
Amaya-no-Hime said:
I'm good, I'm good. Rofl, I refuse to kill myself until DtB season 2 finishes.
Hahaha. Sounds good. I need to watch the first season of that >.>

Yet another thing on my neverending PTW.
Oct 10, 2009 5:27 AM

Offline
Aug 2008
1103
EddieSpaghetti said:
Now, why would I want to kill you?
Haha. I'll just settle for this torture then. D:

HELLOO EDDIEH BTW~
Oct 10, 2009 5:27 AM

Offline
Dec 2008
928
allo
Oct 10, 2009 5:27 AM

Offline
Jul 2008
1374
Hello.
Oct 10, 2009 5:28 AM

Offline
Dec 2008
928
lol @ the casablanca reference in railgun 2
Oct 10, 2009 5:29 AM
Offline
Nov 2007
2010
Kirky said:
Amaya-no-Hime said:
I'm good, I'm good. Rofl, I refuse to kill myself until DtB season 2 finishes.
Hahaha. Sounds good. I need to watch the first season of that >.>

Yet another thing on my neverending PTW.
I know what you mean XD

But yeah, I need someone in GSTS who'll fangirl DtB with me. Unfortunately, it seems as if no one's seen it... D:

EddieSpaghetti said:
Ello.
Ow are you?
Oct 10, 2009 5:29 AM
Offline
Oct 2007
1412
Oct 10, 2009 5:30 AM

Offline
Aug 2008
1103
Avarance said:
lol @ the casablanca reference in railgun 2
wanna watchhh :<

Amaya-no-Hime said:
I know what you mean XD But yeah, I need someone in GSTS who'll fangirl DtB with me. Unfortunately, it seems as if no one's seen it... D:
Hehehe. Good luck with that luff~
Oct 10, 2009 5:32 AM

Offline
Jul 2008
1374
@Amaya.

Not bad ty, how are you?
Oct 10, 2009 5:32 AM

Offline
Dec 2008
928
Oct 10, 2009 5:35 AM

Offline
Jul 2008
1374
I've been to Casablanca before.

Not much to see there.
Oct 10, 2009 5:35 AM

Offline
Aug 2008
1103
Naisuuu.

I still wanna watch Kimi ni Todoke~
Oct 10, 2009 5:36 AM

Offline
Apr 2007
520
forlacik said:


Oct 10, 2009 5:36 AM

Offline
Jul 2008
1374
Except this.

Oct 10, 2009 5:37 AM

Offline
Dec 2008
928
alah ackbar
Oct 10, 2009 5:38 AM

Offline
Aug 2008
1103
8<:B
Oct 10, 2009 5:39 AM

Offline
Jul 2008
1374
Avarance said:
alah ackbar
That place is huggggggggggggggggggggggge
Oct 10, 2009 5:39 AM
Offline
Nov 2007
2010
Kirky said:
Naisuuu.

I still wanna watch Kimi ni Todoke~
Gooo gooooooo

It was AWESOME.

EddieSpaghetti said:
@Amaya.

Not bad ty, how are you?
Fine~
I've got a bit of a headache, but it's nothing that'll last for long.

Kirky said:
Hehehe. Good luck with that luff~
Thanks~

Hmm... Maybe I should pressurize someone into watching the whole first season...
*rubs hands together*
Oct 10, 2009 5:39 AM

Offline
Jul 2008
1374
And the carpets were very thick.
Oct 10, 2009 5:39 AM

Offline
Dec 2008
928
why were you in casablanca anyway
Oct 10, 2009 5:40 AM
Offline
Oct 2007
1412
EddieSpaghetti said:
Except this.

meh
Oct 10, 2009 5:40 AM
Offline
Nov 2007
2010
Avarance said:
alah ackbar
ROFL
Oct 10, 2009 5:40 AM

Offline
Jul 2008
1374
Avarance said:
why were you in casablanca anyway
My dad is Moroccan.
This topic has been locked and is no longer available for discussion.
Pages (200) « First ... « 119 120 [121] 122 123 » ... Last »

More topics from this board

» Tell the time! v2 ( 1 2 3 4 5 ... Last Page )

Kunii - Feb 19, 2024

3170 by mr_linear »»
28 seconds ago

» Sing to the User Above ( 1 2 3 4 5 ... Last Page )

YaoiMaster - Nov 5, 2018

533 by viraat_pirate »»
5 minutes ago

» Say something to the user above you using your voice ( 1 2 3 4 5 ... Last Page )

Habibi97 - Aug 28, 2015

7713 by viraat_pirate »»
11 minutes ago

» A - Z Pokémon part 2 ( 1 2 3 4 5 ... Last Page )

Karinara - Jun 26, 2024

5231 by Meldemort »»
24 minutes ago

» Count until a(n) Mod/Admin posts v47 ( 1 2 3 4 5 ... Last Page )

Fluffygreygrass - Oct 20

260 by Meldemort »»
24 minutes ago
It’s time to ditch the text file.
Keep track of your anime easily by creating your own list.
Sign Up Login