Destination *create( char *code ){
Destination * p = (Destination*) malloc(sizeof(Destination));
strcpy(p->airportCode,code);
p->next=NULL;
}
Why it's showing " Control reaches end of non-void function "
// You are getting that error because you are not returning a value from function // so, return p from function to fix the error Destination *create( char *code ){ Destination * p = (Destination*) malloc(sizeof(Destination)); strcpy(p->airportCode,code); p->next=NULL; return p; }
Destination *create( char *code ){ Destination * p = (Destination*) malloc(sizeof(Destination)); strcpy(p->airportCode,code); p->next=NULL; } Why it's...
Malloc function
For the prelab assignment and the lab next week use malloc
function to allocate space (to store the string) instead of
creating fixed size character array. malloc function allows user to
allocate memory (instead of compiler doing it by default) and this
gives more control to the user and efficient allocation of the
memory space.
Example
int *ptr
ptr=malloc(sizeof(int)*10);
In the example above integer pointer ptr is allocated a space of
10 blocks this is same as creating...
Modify the below code to fit the above requirements:
struct node
{
char data;
struct node *next;
struct node *previous;
} *front, *MyNode, *rear, *MyPointer, *anchor *Valuenode ;
typedef struct node node;
int Push(char input)
{
if(IsFull()==1)
{
printf("The queue is full. Enter the ‘^’ character to
stop.\n");
return -1;
}
else if (IsFull()==-1)
{
node *MyNode=(node*)malloc(sizeof(node));
MyNode->data=input;
rear->next=MyNode;
MyNode->previous=rear;
MyPointer=rear=MyNode;
return 1;
}
else
{
node *MyNode=(node*)malloc(sizeof(node));
node *anchor=(node*)malloc(sizeof(node));
MyNode->data=input;
MyPointer=rear=front=MyNode;
MyNode->previous=NULL;
MyNode->next=NULL;
anchor->next=MyNode;
return 0;
}
}
char...
In c programming The Consumer Submits processing requests to the producer by supplying a file name, its location and a character. It also outputs the contents of the file provided by the producer to the standard output. The Producer Accepts multiple consumer requests and processes each request by creating the following four threads. The reader thread will read an input file, one line at a time. It will pass each line of input to the character thread through a queue...
Following changes need to be made, and the code for each is provided: (1) Modify newMovieReviewNode(), this time the newly allocated review should get an empty linked list of scores ReviewNode *newMovieReviewNode() { /* * This function allocates a new, empty ReviewNode, and initializes the * contents of the MovieReview for this node to empty values. * The fields in the MovieReview should be set to: * movie_title="" * movie_studio="" * year = -1 * BO_total = -1 * score...
Writing a program in C please help!! My file worked fine before but when I put the functions in their own files and made a header file the diplayadj() funtion no longer works properly. It will only print the vertices instead of both the vertices and the adjacent like below. example input form commnd line file: A B B C E X C D A C The directed edges in this example are: A can go to both B and...
****Using C and only C****
I have some C code that has the function addRecord, to add a
record to a linked list of records. However, when I run it, the
program exits after asking the user to input the address. See
picture below:
Here is my code:
#include<stdio.h>
#include<stdlib.h>
struct record
{
int accountno;
char name[25];
char address[80];
struct record* next;
};
void addRecord(struct record* newRecord) //Function For Adding
Record at last in a SinglyLinkedList
{
struct record *current,*start,*temp;...
Create a UNIX makefile for the following C
program:
//convert.c
char toUpper(char c){
if(c>='a' && c<='z')
return c-32;
return c;
}
//converting sentance to upper
void convertSentence(char *sentence){
int i=0;
while(sentence[i]!='\0'){
//convert to upper for each character
sentence[i] = toUpper(sentence[i]);
i++;
}
}
//converting all sentences into uppercase
void convertAll(char **sentenceList, int numOfSentences){
int i=0;
while(i<numOfSentences){
//calling convertsentence function to conver uppercase
convertSentence(sentenceList[i]);
i++;
}
}
sentences.c
#include<stdio.h>
#include<stdlib.h>
#include "convert.c"
int main(){
//declaring character array
char **mySentences;
int noOfSentences;...
IN C PROGRAMMING. PLEASE INCLUDE COMMENTS
#include
#include
#include
typedef struct Contact_struct {
char myName[20]; //name of this Contact
int numGoals;
struct Contact_struct* next; //pointer to the next Contact
} Contact;
//Contact Constructor
void Contact_Create(Contact* thisContact, char thisName[], int
thisGoals, Contact* nextContact) {
strcpy(thisContact->myName,thisName);
thisContact->numGoals = thisGoals;
thisContact->next = nextContact;
}
void Contact_PrintList(Contact* headContact){
Contact* currContact = headContact;
while (currContact != NULL){
printf("%s has scored %d goals\n",currContact->myName,
currContact->numGoals);
currContact = currContact->next;
}
}
int Contact_SumGoals(Contact* headContact){
//Develop Functionality for Contact_SumGoals...
Working on a program where my task is to implement a library (as a set of source and header files, documentation, and a Makefile) that provides a few useful functions for working with a counted string data structure. And one of the functions that needs to be written is described below but I am having a little difficulty writing it. Program needs to be written in C. void kstrcat(kstring *destp, kstring src) Concatenates str onto the end of *destp. First...
Can you help with this C programming question. I have provided
the skeleton code below along with the Stack/Data/Process Class for
you to see/reference. Along with the Stack/Data type
definition.
**SKELTON CODE**
#include
#include
#include
Stack* concat_stack(Stack *s1, Stack *s2) {
//your code here
return NULL;
}
**STACK CLASS FOR YOU TO REFERENCE**
#include
#include
#include
#include
Stack* create_stack(int stack_capacity) {
Stack *s = (Stack*) malloc(sizeof(Stack));
if (stack_capacity < 1) {
fprintf(stderr, "Error(create_stack): invalid capacity, set to
10\n");
s->capacity =...