NO MALLOC & NO USE OF [ ]
C need to parse a file and update array of structs while i do it.
The program reads input from stdin byte by byte (the bytes are from 0 to 255 and each byte represents an ascii symbol value) and each time the a byte occurs it the num_occurences field in the NODE struct must increase.
this is the struct
typedef struct node {
int num_occurences;
short symbol;
} NODE;
this is the array
NODE *node_symb[257];
please help me, again I need to traverse stdin byte by byte and increment the value of num_occurences each time the symbol is repeated. the array is empty in the beginning. I don't know how to do this please help.
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
typedef struct node {
int num_occurences;
short symbol;
} NODE;
int main()
{
NODE node_symb[257];
short byte;
int count = 0,i=0,found=-1;
while ((byte = fgetc(stdin)) != EOF)
{
if (count == 0)
{
//node_symb[count]= (NODE*)malloc(sizeof(NODE));
(node_symb +
count)->symbol = byte;
(node_symb+count)->symbol = byte;
(node_symb +
count)->num_occurences = 1;
++count;
}
else
{
for (i = 0; i
< count; i++)
{
if ((node_symb+i)->symbol == byte)
{
found = i;
break;
}
}
if (found ==
-1)
{
(node_symb + count)->symbol = byte;
(node_symb+count)->num_occurences = 1;
(node_symb + count)->symbol= byte;
++count;
found = -1;
}
else
{
++(node_symb+i)->num_occurences;
found = -1;
}
}
}
for (int i = 0; i < count; i++)
{
if((node_symb+i)->symbol == '\n')
{
printf("character newline found %d times \n",
(node_symb+i)->num_occurences);
}
else if((node_symb+i)->symbol == 32)
{
printf("character space found %d times \n",
(node_symb+i)->num_occurences);
}
else
printf("character %c found %d times
\n", (node_symb+i)->symbol,
(node_symb+i)->num_occurences);
}
}
=========================
//my input file
abcabda
bng da#@_
jh
//output
character a found 4 times
character b found 3 times
character c found 1 times
character d found 2 times
character newline found 2 times
character n found 1 times
character g found 1 times
character space found 2 times
character # found 1 times
character @ found 1 times
character _ found 1 times
character j found 1 times
character h found 1 times
======================
//psl provide +ve rating , thanks
IN MIPS PLEASE. Need help writing a MIPS program that reads from a text file named "input.txt" and places it in a buffer. A buffer of 80 bytes is more than enough. Before you call your function, set $a0 equal to the address of the filename and $a1 to the address of the buffer where data is stored. The function should return the number of bytes read in $v0. In the main program, print an error message and terminate the...
Hi, I need to make a program in C that reads the type of currency and organizes them into stacks based on currency which can be read back. This is what I have so far, can I get help finishing it? #include <stdio.h> #include <stdlib.h> const float POUND = 1.31; const float YEN = 0.0091; const float RUPEE = 0.014; const float EURO = 1.11; char c; int currValue; float exchangeValue; float finValue; int printValue; struct node { int...
URGENT. Need help editing some C code. I have done most of the code it just needs the following added: takes an input file name from the command line; opens that file if possible; declares a C struct with three variables; these will have data types that correspond to the data types read from the file (i.e. string, int, float); declares an array of C structs (i.e. the same struct type declared in point c); reads a record from the...
This is for C++ Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along with the number of times it occured. All non-alphabetic characters must...
Need some help creating a bubble sort for my linked list in C. Here are the structs used in my code: struct simulation { void *list; int et; /* in seconds */ }; struct plane { double x, y, altitude; char callsign[15]; struct simulation *sim; }; Here is the struct used in my linked list: struct Node { void *data; struct Node *next; }; Here is my insert function: //ComparisonFunction and FILE not...
C++ need help with vector. I have a text file and input it's content into a struct that holds an array for each entry as a string type. for example: struct container{ string ID[10000]; string anotherID[10000]; } in the text file there is a huge list that looks something like this: 1 abc 3 xyz 1 abc 1 xyz How can I use a vector to sort these so I can get an output like ID: 1 and anotherID: abc...
I
need help and tied to the requirements please. Exactly part B and
D.
2. (20pts) Consider the following linked list (LL is pointing to the sentinel node): 2. (20 points) Consider the following linked list (LL is pointing to the sentinel node) NULL Assume each node is a struct node(int data; struct node 'next) (a) what will be printed by the following statement? printf("%d %d\n",LL-> next-> next-> data, LL-> next->data); Part A: What will be printed by the following...
I need help coding this in C •Your program should start by asking the user how many nodes will be in the network. Nodes should be implemented by a node struct and maintained in a Linked List. •Each node should maintain all packets that have been generated and are ready to be be transmitted (one at a time). Packets should be implemented by a packet struct and maintained in a Linked List.
Trying to figure out what needs to be in the headers.h file. I have written the print function. Qualities in header file main() needs insertionSort() and mergeSortWrapper() Both insertionSort() and mergeSortWrapper() need print(). Please copy-and-paste the following files (0 Points): insertionSort.c /*--------------------------------------------------------------------------* *---- ----* *---- insertionSort.c ----* *---- ----* *---- This file defines a function that implements insertion ----* *---- sort on a linked-list of integers. ----* *---- ----* *---- ---- ---- ---- ---- ---- ---- ---- ---- ----* *----...
IN C ONLY As mentioned earlier there are two changes we are going to make from lab 5, The file you read into data structures can be any length. studentInfo array will be stored in another struct called studentList that will contain the Student pointer and current length of the list. Sometimes data can be used in structs that correlate between variables so it's convenient to store the data in the same struct. Instead of tracking a length variable all...