C / C++ Code Portfolio


exit(EXIT_FAILURE); } // Return pointer to allocated memory return



Download 112,15 Kb.
bet26/30
Sana01.03.2022
Hajmi112,15 Kb.
#475852
1   ...   22   23   24   25   26   27   28   29   30
Bog'liq
dddd

exit(EXIT_FAILURE);
}
// Return pointer to allocated memory
return(vp);
}

static List *CreateListNode(const char *str)
{
// allocate memory for a new node
List *newNode = (List *)SafeMalloc(sizeof(List));
// determine the length of the string; add 1 to include the string terminator '\0'
size_t strLength = strlen((const char *)str) + 1;
// allocate enough memory to store the string into the node
char *strAlloc = (char *)SafeMalloc(strLength);
// copy the string into the newly allocated memory
memcpy(strAlloc, str, strLength);
// point the new node string to the newly allocated memory containing the string
newNode->str = strAlloc;
// set the node count to 1, as this is the first time the string has appeared
newNode->count = 1;
return newNode;
}

static void Insert(List **pt, List *newNode)
{
// set the new node's next member to point to the previous node
newNode->next = *pt;
*pt = newNode;
}

List *CreateList(FILE *fp)


{
// declare firstNode, which will always be the first node of the list, and currentNode
List *firstNode = NULL, *currentNode = NULL;
// declare a character array that will temporarily store each new string as it is read in from the file
char nextString[MAX_STRING_LENGTH];
// read in the next string in the file, stop if EOF is encountered
while (fscanf(fp, "%255s", nextString) != EOF)
{
// begin by noting that we have not yet found a matching string.
int stringFound = 0;
// for every node
for (; currentNode != NULL; currentNode = currentNode->next)
{
// check if the new string from the file matches the string stored in the node if so...
if (strcmp(currentNode->str, nextString) == 0)
{
// increment the node count, indicating that we have found a duplicate string
currentNode->count++;
// specify that we have found a match
stringFound = 1;
// reset the node search to again start at the first node
currentNode = firstNode;
// break out of the for loop, we have found a match, no need to keep searching

Download 112,15 Kb.

Do'stlaringiz bilan baham:
1   ...   22   23   24   25   26   27   28   29   30




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish