C Programming Assignment Help | Online tutoring | Help with Homework

C programs are not that easy to write. Students needs to submit their assignment in less time and hence they find it difficult to complete them. We are here to offer all sorts of C programming homework help to students as well as working professionals. Our expert C programming tutors are efficient and highly educated. They know the complexities involved when they provide help with C programming assignment and hence they provide easy and to the point C programming project help. Our experts are also available 24*7 to offer online C programming project help. Providing help with C programming homework is a easy task for us and we provide C programming assignment help, well within the deadline. For the best C programming homework help, see the samples on this page.

If you require help with your C programming assignment or are looking for a C programming online tutor to help you complete your C programming homework then we can do that for you.

For C Programming assignment our Programming Homeworks help is the consistent and foremost online solution. C Programming is one of the basic and widely used programming languages across the universities. Hence, C Programming homework and assignments form the major portion of students’ academic curriculum.

Data processing

Objective

You are given list of binary data files from the NIH L1000 project. Each file contains 501 sets of values. The index 0 is reserved for values that are errors. The other 500 sets are florescent bead intensity values from the experiments. Your program will scale these intensity values to previously measured values using older DNA chip technology.

The command:

normalize_L1000 wells_list

should read the list and generate a new set of files which are normalized with a ‘.norm’ added to the original name.

Basic methodology

The first 10 bead types are standards where the values on the old scale are known. You will find the median data value for each of these bead types, take the logarithm and then find the straight line that fits the logarithm of the median values to the values on the old scale. The equation of the line is used to transform all 500 sets of bead fluorescence values to the same scale as the older DNA chip values. These “normalized” values will be written out to a new binary file.

Binary input file format

The input data files are binary files containing 16 bit integer values (0..32767) The format is a header consisting of 2 16 bit integer numbers that describe the index of the set (bead id) and the number of intensity values measured. This is followed by the data values for that bead id. Each data values is also a 16 bit integer This is repeated for all 500 bead types.

Binary output file format

You will output a binary function in a similar format – the same header consisting of 2 16 bit integer numbers that describe the index of the set (bead id) and the number of intensity values measured followed by the data values in float format.

Input List format

The list consists of a single filename on each line. Assume the filename has no spaces and is terminated with a unix ‘\n’

Files in the tarball

Makefile – a set of flags and the final link rule is given to you. The rest is essentially the same as the last assignment except that the names of the files are different.

lincsdata.c – a skeleton is provided with the struct that is to be used and the related functions/methods that need to be written. The idea is to use this file like you would a class in Java. This file will have methods that read in the binary file, calculate the straight line equation, normalize the data and write out the new binary file. All the functions specific to the struct are static mimicking private methods except for the normalize function.

normalize_L1000.c – This is the main routine. It reads in the list of binary files, and calls the normalize function.

median.c – This calculates the median value of a set of values. Almost all of it is given to you – you must figure out how to modify the standard selection.c implementation to work with int16_t type.

regression.c – This is given to you. Calculates the slope and intercept of the best fitting straight line through the data.

median.h, regression.h, normalize.h – These header files are given to you.

A_wells – a directory with the binary files corresponding to beads in wells A01 to A24

wells_list – a list of these files that will be the input to your software

normalized_A_wells – This contains 5 correct output files. This is to allow you to check your output. The unix command diff can be used to compare these files with your output.

makefile

all:
    gcc *.c -o normalize_L1000 -lm
clean:
    rm -f normalize_L1000

 

lincsdata.c

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "lincsdata.h"
#include "regression.h"
#include "median.h"

 /*this will have the normalize prototype which is the function we are exposing*/
#define NINT16 32768

static float logStandardValues[10]={5.6438561898,6.6438561898,7.6438561898,8.6438561898,9.2288186905,9.9657842847,10.9657842847,11.5507467854,12.2877123795,12.7731392067}; /*standard values for normalization - these will be the yvalues in the regression call*/

static float logx[NINT16]; /*precalculated lookup table for log base 2*/;

typedef struct {
    char *infilename;
    char *outfilename;
    int16_t *rawDataBlock; /*raw data numbers*/ 
    int16_t *rawData[502];  /*pointers to where the raw data number starts for each bead type*/
                           /*an extra pointer is used to point one past the end of the block so that pointer arithmetic can be used
                            * to find the number of each type of beads */
} lincsData;

static void construct(lincsData *ldata, char *infilename,char *outfilename);
static void allocate_and_read(lincsData *ldata);
static void convert_and_output(lincsData *ldata);
static void destruct(lincsData *ldata);

static void initialize_logx();

static void construct(lincsData *ldata, char *infilename,char *outfilename){
    /*about 3 lines of code*/
    /*initialize the filenames*/
    /*call allocate and read*/
    ldata->infilename = infilename;
    ldata->outfilename = outfilename;
    allocate_and_read(ldata);
}
static void allocate_and_read(lincsData *ldata){
    FILE *fin;
    int i;
    int16_t head[2];
    int nValues[502];
    int total_size = 0;

    memset(nValues, 0, sizeof(nValues));
    memset(ldata->rawData, 0, sizeof(ldata->rawData));

    /*open read in data and allocate as given in  class code read_lincs_3ways for block of text plus pointers*/
    /*about 25 lines of code changed to use parameters in the struct*/
    fin = fopen(ldata->infilename, "r");
    /* calculate the total size for data */
    while (fread(&head, 2 * sizeof(int16_t), 1, fin)) {
      total_size += head[1] * 2;
      nValues[head[0]] = head[1];
      fseek(fin, head[1] * 2, SEEK_CUR);
    }
    fseek(fin, 0, SEEK_SET);

    ldata->rawDataBlock = (int16_t *)malloc(total_size);

    /* merge the nvalues, so we know the offset for each bead id */
    for (i = 1; i <= 500; i++) {
      nValues[i] += nValues[i - 1];
      ldata->rawData[i] = ldata->rawDataBlock + nValues[i - 1];
    }
    ldata->rawData[501] = ldata->rawDataBlock + nValues[500];

    /* load the raw data*/
    while(fread(&head, 2 * sizeof(int16_t), 1, fin)) {
      int16_t *offset = ldata->rawData[head[0]];
      for (i = 0; i < head[1]; i++) {
        fread(offset + i, sizeof(int16_t), 1, fin);
      }
    }
    fclose(fin);
}

static void convert_and_output(lincsData *ldata){
    /*about 20-25 lines of code*/
    int i;
    float logMedians[11];
    float slope, intercept;
    FILE *fout;

    /*initialize the log2 lookup table if the last element of log2 is zero*/
    if (logx[NINT16 - 1] == 0) {
      initialize_logx();
    }

    /*loop through indices 1 to 10*/
    /*calculate medians for rawData in indices 1 to 10 using median function
     and save the log of the medians logx[median] to logMedians[i]*/
    /*you will be passing ldata->rawData[i] as the values array ldata->rawData[i+1]-ldata->rawData[i] as nValues to the median function*/
    for (i = 1; i <= 10; i++) {
      int16_t m = median(ldata->rawData[i], ldata->rawData[i+1]-ldata->rawData[i]);
      logMedians[i] = logx[m];
    }

    /*find slope and intercept using y as logStandardValues array declared as a gloabl and x as logMedians array*/
    regression(&logMedians[1], logStandardValues, 10, &slope, &intercept);

    /*open the outputfile*/ 
    fout = fopen(ldata->outfilename, "w");

    /*loop through all the bead types 0 to 500*/
    for (i = 1; i <= 500; i++) {
        /*find the number of beads of that type by pointer arithmetic*/
        int num = ldata->rawData[i + 1] - ldata->rawData[i];

    /*if the number of bead is not zero*/
        if (num > 0) {    
    /*copy i to a int16_t variable*/
            int16_t head[2];
            int j;

            head[0] = i;
            head[1] = num;
    /*copy the number of beads to a int16_t variable*/
    /*write these values out using fwrite*/
            fwrite(head, sizeof(int16_t) * 2, 1, fout);

    /*loop through the rawData for the bead number i*/
            for (j = 0; j < num; j++) {
 /*convert raw data to the normalize data using formula normData=slope*log2[ldata->rawData[i][j]]+intercept */ 
              float normData=slope*logx[ldata->rawData[i][j]]+intercept;

 /*write this out with fwrite*/
              fwrite(&normData, sizeof(float), 1, fout);
            }
        }
    }
 /*close the outputfile*/
    fclose(fout);

}
static void destruct(lincsData *ldata){
 /*one line of code*/
  free(ldata->rawDataBlock);
}

static void initialize_logx(){
    int i;
    float invlog2=1.0/log(2);
    for (i=1;i<NINT16;i++)
     logx[i]=log(i)*invlog2;
}

int normalize(char *input_file,char *output_file){
    /*public method that allocates the struct, converts and outputs the data and deallocates the struct and */
    /*4 lines of code*/
    lincsData ldata;
    /*call the construct, convert_and_output destruct function/methods */
    construct(&ldata, input_file, output_file);
    convert_and_output(&ldata);
    destruct(&ldata);
    return(1);

}

Students in general struggle complete C Programming assignments on their own and need a professional guidance to complete C Programming projects. We, as a dedicated programming online help provider are aware of this and hence have accordingly designed the C programming services section.

lincsdata.h

int normalize(char *input_file,char *output_file);

 

median.c

#include <stdint.h>
#include <stdlib.h>
#include <string.h>

typedef int16_t elem_type;

static elem_type quick_select(elem_type arr[], int n);

int16_t median(int16_t *values, int nValues){

    /*allocate and make copy of values*/
    int16_t *myValues;
    int16_t medianValue;
    if(!(myValues=malloc(sizeof(int16_t)*nValues))){
        exit(0);
    }
    memmove(myValues,values,nValues*sizeof(int16_t));
    medianValue=quick_select(myValues,nValues); 
    free(myValues);
    /*call quickselect.c routine from http://ndevilla.free.fr/median/median/index.html */

    /*deallocate*/
    return(medianValue);
}

/*
 *  This Quickselect routine is based on the algorithm described in
 *  "Numerical recipes in C", Second Edition,
 *  Cambridge University Press, 1992, Section 8.5, ISBN 0-521-43108-5
 *  This code by Nicolas Devillard - 1998. Public domain.
 */

#define ELEM_SWAP(a,b) { register elem_type t=(a);(a)=(b);(b)=t; }

elem_type quick_select(elem_type arr[], int n) 
{
    int low, high ;
    int median;
    int middle, ll, hh;

    low = 0 ; high = n-1 ; median = (low + high) / 2;
    for (;;) {
        if (high <= low) /* One element only */
            return arr[median] ;

        if (high == low + 1) {  /* Two elements only */
            if (arr[low] > arr[high])
                ELEM_SWAP(arr[low], arr[high]) ;
            return arr[median] ;
        }

    /* Find median of low, middle and high items; swap into position low */
    middle = (low + high) / 2;
    if (arr[middle] > arr[high])    ELEM_SWAP(arr[middle], arr[high]) ;
    if (arr[low] > arr[high])       ELEM_SWAP(arr[low], arr[high]) ;
    if (arr[middle] > arr[low])     ELEM_SWAP(arr[middle], arr[low]) ;

    /* Swap low item (now in position middle) into position (low+1) */
    ELEM_SWAP(arr[middle], arr[low+1]) ;

    /* Nibble from each end towards middle, swapping items when stuck */
    ll = low + 1;
    hh = high;
    for (;;) {
        do ll++; while (arr[low] > arr[ll]) ;
        do hh--; while (arr[hh]  > arr[low]) ;

        if (hh < ll)
        break;

        ELEM_SWAP(arr[ll], arr[hh]) ;
    }

    /* Swap middle item (in position low) back into correct position */
    ELEM_SWAP(arr[low], arr[hh]) ;

    /* Re-set active partition */
    if (hh <= median)
        low = ll;
        if (hh >= median)
        high = hh - 1;
    }
}

#undef ELEM_SWAP

    /*copy and modifiy quickselect.c routine from http://ndevilla.free.fr/median/median/index.html*/

Our C Programming services cover entire gamut of topics such as Arrays, Functions, Pointers, Data Structures etc. Diverse pool of experienced C Programming experts ensures that all of these topics are well covered and we would be able to provide online help for any assignment or project in C Programming.

median.h

#include <stdint.h>
int16_t median(int16_t *values, int nValues);

 

normalize_L1000.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lincsdata.h"

int main(int argc,char **argv){
  FILE *fin;
  char line[512];
  char output[512];

  if (argc == 1) {
    printf("Usage: %s wells_list\n", argv[0]);
    return -1;
  }

 /*read in the input list from argv[1]*/
  fin = fopen(argv[1], "r");
  if (fin == NULL) {
    printf("Error: could not open file %s.\n", argv[1]);
    return -1;
  }

 /*read in each file line by line*/
  while (fgets(line, sizeof(line), fin) != NULL) {
    /* remove \n if any */
    int len = strlen(line);
    if (len > 0 && line[len - 1] == '\n') {
      line[len - 1] = '\0';
      len = len - 1;
    }
    if (len == 0) continue; /* skip empty line */
    /*call the normalize function defined in lincsdata.h*/
    /*the outputfilename will be the inputfilename with ".norm" appended to it*/
    /* now construct the output file name */
    snprintf(output, sizeof(output), "%s.norm", line);
    normalize(line, output);
  }
  fclose(fin);

  return(1);
}

 

regression.c

#include <stdio.h>
int regression(float *x,float *y,int n,float *slope, float *intercept){
    /*using the formula in http://stackoverflow.com/questions/6846467/where-can-i-find-source-code-to-do-a-simple-linear-regression */
    int i;
    float sy=0,sx=0,sxx=0,syy=0,sxy=0;
    for (i=0;i<n;i++){
        const float xvalue=x[i];
        const float yvalue=y[i];
        sx+=xvalue;
        sy+=yvalue;
        sxx+=xvalue*xvalue;
        sxy+=xvalue*yvalue;
        syy+=yvalue*yvalue;
    }
    if(!((n*sxx)-sx*sx)){
  *intercept=0;
  *slope=0;
        return(0);
    }   
    *intercept= (sy*sxx-sx*sxy)/(float)(n*sxx-sx*sx);
    *slope= (n*sxy-sx*sy)/(float)(n*sxx-sx*sx);
    return(1);
}

Our experts are well qualified and have years of experience solving the C Programming project for the students. They bring the expertise while preparing the solutions by putting together the well commented codes. The simplistic approach followed by them allows students to understand the complex concepts.

regression.h

int regression(float *x,float *y,int n,float *slope, float *intercept);

You should find a sample C programming homework, that illustrates the quality of the work we can do for you.

Bus Schedules

Perth’s Public Transport Authority (PTA) provides public access to its scheduled times, stop locations, and route information from its webpage www.transperth.wa.gov.au/About/Spatial-Data-Access.
The data is released as a collection of inter-related textfiles following the Google Transit Feed Specification (GTFS),
which is also used by many other public transport companies,
worldwide.

You will need to download your own copy of the data (about 90MB) by clicking on the first link “By downloading the data you are agreeing to the terms of the License…” \ The currently available data is valid until November 25th (after the project’s due date).

The primary task

The project requires you to develop a C99 program, named whichbus, which uses GTFS-format data to find the shortest travel time between two provided locations. Your program should check for and accept 5 command-line arguments:

  • the name of a directory containing a set of GTFS files, and
  • a starting and an ending location (as pairs of latitude and > longitude coordinates, typically home and work),

and produce plain-text output describing the “best” single-segment public transport route that should be taken to travel between the two locations. The starting time of the journey should be taken from the environment variable named LEAVEHOME. This enables you to develop and test your program by holding the day and time constant. We will assume that all services run every day. However, ensure that a 3-character ‘day’ still appears at the beginning of the LEAVEHOME environment variable. The example, below, shows how you can set this environment variable to the current day, hour and minute, and then export it to your program.

The definition of the “best” route is the one requiring the minimum total journey time, consisting of single-segment:

  • walking from the starting point to the single bus, train, or > ferry stop;
  • travel time on the bus, train, or ferry;
  • time walking from the final stop to the required destination.

Representative executions and outputs of your program, requesting single-segment journeys – one by bus and another by rail – are:

prompt> export LEAVEHOME="\`date '+%a %H:%M'\`" 
prompt> echo \$LEAVEHOME  Wed 10:56
prompt> ./whichbus transperth -32.014402 115.758259 -31.981039 115.819120
10:56 walk 316m to stop 10349 "Stirling Hwy After Wellington St"
11:04 catch bus 98 to stop 10380 "Stirling Hwy After Clifton St"
11:23 walk 750m to destination
11:36 arrive
prompt> export LEAVEHOME="Mon 14:00"
prompt> ./whichbus transperth -31.747750 115.766545 -31.952804 115.854921
14:00 walk 332m to stop 99871 "Joondalup Stn Platform 1"
14:07 catch rail "Joondalup Line" to stop 99602 "Perth Underground Stn
Platform 2"
14:33 walk 336m to destination
14:39 arrive

Your program should allow the traveler sufficient time to walk from their starting location (typically their home) to, say, a nearby bus-stop. Amazingly, people can walk in straight lines at a constant speed of one metre-per-second, between any two points (through buildings!), and buses are always on time! No walking segment should be longer than 1000m.

\

In addition, in order to reduce the number of potential journeys that need searching, the actual segment on a bus, train, or ferry, must commence within one hour of leaving the starting location (home).

An extended task

You can achieve full marks, 20/20, for the project by successfully implementing the primary task, above. In addition, you may wish to attempt an extended task to recover any lost marks. you may wish to attempt an extended task to recover any lost marks The extended task permits a journey to consist of two-segments, on any combination of bus, train, or ferry. A two-segment journey would involve additional steps:

  • getting off the first bus, train, or ferry;
  • walking to transfer to another bus, train, or ferry;
  • waiting for the connection to arrive;
  • traveling on a second bus, train, or ferry towards the destination; > and
  • (as before) walking from the final stop to the required destination.

The representative execution and output of your program, requesting a journey involving a train segment and then a bus segment, is:

prompt> ./whichbus transperth -32.029674 115.755018 -31.981039 115.819120 
11:08 walk 305m to stop 99341 "North Fremantle Stn Platform 1"
11:15 catch rail "Fremantle Line" to stop 99281 "Claremont Stn Platform1"
11:25 walk 165m to stop 19604 "Gugeri St Before Bay View Tce"
11:30 catch bus 102 to stop 26723 "Mounts Bay Rd After Hampden Road"
11:41 walk 620m to destination
11:51 arrive

If you successfully achieve the extended task, you can recover up to 5 marks that may have been lost while attempting the primary task. The
maximum mark for your project submission will still be 20/20.

We ensure that all the solutions prepared by us are completely plagiarism free and adhere to the referencing styles as instructed by the students. With all these distinct features, we assure you excellent scores in your C Programming assignment. So, if you are struggling with C Programming homework or need any help with C Programming project, then all you need to do is to email us your requirements and we will ensure that you receive quality help on immediate basis.

Program requirements

Projects will be marked using an automatic marking program (for correctness) and by visual inspection (for good programming practices). It is thus important that your program produces its output in the correct format. Only lines commencing with digits (for times) will be considered valid output during the testing – thus, you can leave your “last minute” debugging output there if you wish.

Each line of output consists of a number of fields, which may be separated by one-or-more space or tab characters. The names of bus, train, and ferry stops should be enclosed within double-quotation characters, as the names include spaces. Times should be specified as HH:MM using a 24-hour clock, and no journey (in testing) will span midnight. Distances should be reported as an integer number of metres (truncated, no decimal component), such as 340m.

A program will be provided to enable you to test the correctness of the output format of your program.

Suggested steps for the primary task

  • Read Working effectively in CITS2002
  • Consider how you would travel between the two locations if you were a dumb robot with unlimited time, patience, and energy.
  • Download the GTFS dataset, and skim its documentation webpage. See what is in each textfile, determine which files will be required, and which files not required.
  • Discuss the problem with a colleague (your project partner?) as to how you’d each attack the problem. Merge. Iterate.
  • Too soon for coding? Probably. Code your main() function, checking for and validating the 5 command-line arguments.
  • Find the bus, train, or ferry stops that are within 1000m (walk) of the starting location.
  • Determine which bus, train, or ferry routes use each of those stops, today, after the journey’s starting time.
  • Do any of those bus, train, or ferry routes pass within 1000m (walk) of the destination? Which journey has the shortest total time?

In addition to the assignment and homework help, we also provide C Programming Online tutoring. Students can learn the difficult programming concepts through direct interaction with our C Programming experts. Thus, we are the one point solution for all of your C Programming needs.

Solution to C programming project

 

DistanceCalculation.h

//
//  DistanceCalculation.h
//  GTFS
//
//  Created by admin on 9/17/15.
//  Copyright (c) 2015 Stanfy. All rights reserved.
//

#ifndef GTFS_DistanceCalculation_h
#define GTFS_DistanceCalculation_h

#include <math.h>

double degreesToRadians(double degrees) {
    return degrees * M_PI / 180.0 ;
}

double distanceBetweenLocations(double location1Lat,
                                double location1Lon,
                                double location2Lat,
                                double location2Lon) {
    // Description can be found here. We are just porting this to C :
    // http://www.movable-type.co.uk/scripts/latlong.html
    double earthRadius = 6371000; // metres
    double l1LatRadians = degreesToRadians(location1Lat);
    double l2LatRadians = degreesToRadians(location2Lat);
    double deltaLat = degreesToRadians(location2Lat - location1Lat);
    double deltaLon = degreesToRadians(location2Lon - location1Lon);

    double a = pow(sin(deltaLat / 2), 2) + cos(l1LatRadians) * cos(l2LatRadians) * pow(sin(deltaLon / 2), 2);
    double c = 2 * atan2(sqrt(a), sqrt(1-a));

    double distance = earthRadius * c;
    return distance;
}

#endif

There are multiple unique features which differentiates us from other service providers. We put a strict emphasis on meeting the timelines as communicated by the students and strive to send the solutions well before the deadline.

main.c

//
//  main.c
//  GTFS
//
//  Created by admin on 9/17/15.
//  Copyright (c) 2015 Stanfy. All rights reserved.
//

#include <stdio.h>
#include "DistanceCalculation.h"
#include "StopsDataProvider.h"
#include "StopTimesDataProvider.h"
#include "TripDataProvider.h"

int main(int argc, const char * argv[], const char * envp[]) {
    if (argc < 5 ) {
        printf("Incorrect amount of parameters, terminating program\n");
        return 0;
    }

    char directoryName[255];
    double startLatitude = 0;
    double startLongitude = 0;
    double destinationLatitude = 0;
    double destinationLongitude = 0;
    int dayIndex = -1;
    int minutesStartTime = 0;

    // Setting directory name
    memset(directoryName, 0, 255);
    strcpy(directoryName, (char *)(argv[0]));

    // Setting coordinates
    sscanf((char *)(argv[1]), "%lf", &startLatitude);
    sscanf((char *)(argv[2]), "%lf", &startLongitude);
    sscanf((char *)(argv[3]), "%lf", &destinationLatitude);
    sscanf((char *)(argv[4]), "%lf", &destinationLongitude);

    // Getting environment
    char** env;
    for (env = envp; *env != 0; env++)
    {
        char* thisEnv = *env;
        if (strcmp(strtok_single(thisEnv, "="), "LEAVEHOME") == 0) {
            parseLeaveHomeValue(strtok(NULL, ""), &dayIndex, &minutesStartTime);
            break;
        }
    }
    if (dayIndex == -1) {
        printf("Problem with searching or parsing environment variable 'LEAVEHOME'. Terminating program!");
        return 0;
    }

    // Find suitable stops for start point
    mut_array * startSuitableStops = suitableStopsForCoordinate(directoryName, startLatitude, startLongitude);
    mut_array * destinationSuitableStops = suitableStopsForCoordinate(directoryName, destinationLatitude, destinationLongitude);

    mut_array * startStopPointer = startSuitableStops;
    mut_array * destinationStopPointer = destinationSuitableStops;

    struct TripStruct * optimalTripStruct = NULL;
    struct StopStruct * optimalStartStop = NULL;
    struct StopStruct * optimalDestinationStop = NULL;
    int foundOptimalJourneyFinishTime = -1;

    while (startStopPointer) {
        if (startStopPointer->value) {
            struct StopStruct * startStopValue = startStopPointer->value;
            int arrivalTimeAtStartStop = minutesStartTime + (int)(distanceBetweenLocations(startStopValue->latitude, startStopValue->longitude, startLatitude, startLongitude) / 60 + 1);
            while (destinationStopPointer) {
                if (destinationStopPointer->value) {
                    struct StopStruct * destinationStopValue = destinationStopPointer->value;
                    struct TripStruct * shortestTrip = suitableTripForStopsAndStartTime(directoryName, arrivalTimeAtStartStop, startStopValue->stopId, destinationStopValue->stopId);
                    if (shortestTrip) {
                        int walkDurationFromDestinationStop = (int)(distanceBetweenLocations(destinationLatitude, destinationLongitude, destinationStopValue->latitude, destinationStopValue->longitude) / 60 + 1);
                        int finalJourneyTime = shortestTrip->endTrip + walkDurationFromDestinationStop;
                        if ((foundOptimalJourneyFinishTime == -1) || (foundOptimalJourneyFinishTime < finalJourneyTime)) {
                            foundOptimalJourneyFinishTime = finalJourneyTime;
                            optimalTripStruct = shortestTrip;
                            optimalStartStop = startStopValue;
                            optimalDestinationStop = destinationStopValue;
                        }
                    }
                }
                destinationStopPointer = destinationStopPointer->next;
            }
        }
        startStopPointer = startStopPointer->next;
    }

    if (foundOptimalJourneyFinishTime == -1) {
        char timeString[6];
        stringFromMinutes(minutesStartTime, timeString);
        printf("%s not possible\n", timeString);
    } else {
        char routeId[10];
        routeIdForTripId(directoryName, optimalTripStruct->tripId, routeId);
        struct RouteInfo * routeInfo = routeInfoByRouteId(directoryName, routeId);

        // Output generated data
        char startOfJourney[6];
        stringFromMinutes(minutesStartTime, startOfJourney);
        int firstWalkingDistance = (int)distanceBetweenLocations(optimalStartStop->latitude, optimalStartStop->longitude, startLatitude, startLongitude);
        printf("%s walk %dm to stop %s \"%s\"", startOfJourney, firstWalkingDistance, optimalStartStop->stopId, optimalStartStop->stopName);

        char catchTransportTime[6];
        stringFromMinutes(optimalTripStruct->startTrip, catchTransportTime);
        char routeType[20];
        routeTypeStringFromRouteType(routeInfo->routeType, routeType);
        printf("%s catch %s %s to stop %s \"%s\"", catchTransportTime, routeType, routeInfo->routeName, optimalDestinationStop->stopId, optimalDestinationStop->stopName);

        char destinationStopArrivalTime[6];
        stringFromMinutes(optimalTripStruct->endTrip, destinationStopArrivalTime);
        int secondWalkingDistance = (int)distanceBetweenLocations(destinationLatitude, destinationLongitude, optimalDestinationStop->latitude, optimalDestinationStop->longitude);
        printf("%s walk %dm to destination", destinationStopArrivalTime, secondWalkingDistance);

        char finishTime[6];
        stringFromMinutes(foundOptimalJourneyFinishTime, finishTime);
        printf("%s arrive", finishTime);
    }

    return 0;
}

Our chat and email support ensures that students receive the best in class C Programming help on an instant basis. Adherence to referencing styles such as APA, Harvard etc and well commented codes makes the solution perfect and results in higher grades for the students.

MutableArray.h

//
//  MutableArray.h
//  GTFS
//
//  Created by admin on 9/17/15.
//  Copyright (c) 2015 Stanfy. All rights reserved.
//

#ifndef GTFS_MutableArray_h
#define GTFS_MutableArray_h

#include <stdlib.h>

typedef struct mut_array{
    void * value;
    struct mut_array * next;
} mut_array;

mut_array * newMutArray() {
    mut_array * first = malloc((size_t)sizeof(mut_array));
    first->value = NULL;
    first->next = NULL; //should link to a sentinel
    return first;
}

void  add(mut_array * first, void * value) {
    mut_array * next;
    while((next = first->next) != NULL) {
        first = next;
    }
    next = malloc(sizeof(mut_array));
    first->next = next;
    next->value = value;
    next->next = NULL;
}

void clearMutArray(mut_array * array) {
    struct mut_array * next = array;
    struct mut_array * current = NULL;
    while ((current = next) != NULL) {
        next = current->next;
        free(current->value);
        free(current);
    }
}

#endif

 

StopsDataProvider.h

//
//  StopsDataProvider.h
//  GTFS
//
//  Created by admin on 9/17/15.
//  Copyright (c) 2015 Stanfy. All rights reserved.
//

#ifndef GTFS_StopsDataProvider_h
#define GTFS_StopsDataProvider_h

#include <string.h>
#include <stdio.h>
#include "MutableArray.h"
#include "Utils.h"

struct StopStruct {
    char stopId[20];
    double latitude;
    double longitude;
    char stopName[255];
} StopStruct;

struct StopStruct * parseStopFromString(char * stopString) {
    struct StopStruct * result = malloc(sizeof(StopStruct));
    char * token = strtok_single(stopString, ","); // Location_type
    token = strtok_single(NULL, ","); // ParentStation
    token = strtok_single(NULL, ",");
    if (!token) {
        return NULL;
    }
    strcpy(result->stopId, token); // stop id
    token = strtok_single(NULL, ","); // stop code
    token = strtok_single(NULL, ",");
    if (!token) {
        return NULL;
    }
    strcpy(result->stopName, token); // stop name
    token = strtok_single(NULL, ","); // stop description
    token = strtok_single(NULL, ",");
    if (!token) {
        return NULL;
    }
    sscanf(token, "%lf", &(result->latitude));
    token = strtok_single(NULL, ",");
    if (!token) {
        return NULL;
    }
    sscanf(token, "%lf", &(result->longitude));
    return result;
}

mut_array * suitableStopsForCoordinate(char * folderName, double latitude, double longitude) {
    char filePath[255];
    memset(filePath, 0, 255);
    strcpy(filePath, folderName);
    strcat(filePath, "/stops.txt");
    FILE * stopsFile = fopen(filePath, "r");
    if (!stopsFile) {
        printf("File stops.txt was not found in data folder.");
        return NULL;
    }

    char buffer[500];
    mut_array * suitableStops = newMutArray();
    // Skip first line without handling
    fgets(buffer, 500, stopsFile);
    while (!feof(stopsFile)) {
        // Read single stop, scan it and check distance
        fgets(buffer, 500, stopsFile);
        struct StopStruct * parsedStop = parseStopFromString(buffer);
        if (parsedStop) {
            if (distanceBetweenLocations(latitude, longitude, parsedStop->latitude, parsedStop->longitude) < 1000) {
                add(suitableStops, parsedStop);
            }
        }
    }

    fclose(stopsFile);

    return suitableStops;
}

#endif

We do have facility of the providing multiple iterations of solutions, if the students are not convinced with the answers. So, chat with us and share your requirements through our website.

StopTimesDataProvider.h

//
//  StopTimesDataProvider.h
//  GTFS
//
//  Created by admin on 9/19/15.
//  Copyright (c) 2015 Stanfy. All rights reserved.
//

#ifndef GTFS_StopTimesDataProvider_h
#define GTFS_StopTimesDataProvider_h

#include "MutableArray.h"
#include "Utils.h"

struct TripStruct {
    char tripId[20];
    int startTrip; // time in minutes on start station
    int endTrip; // time in minutes on destination station
};

struct StopTimeRecord {
    char tripId[20];
    char stopId[20];
    int arrivalTimeMinutes;
    int stopSequence;
} StopTimeRecord;

struct StopTimeRecord * parseStopTimeRecord(char * csvRecord) {
    struct StopTimeRecord * parsedRecord = malloc(sizeof(StopTimeRecord));
    char * token = strtok_single(csvRecord, ",");
    strcpy(parsedRecord->tripId, token);
    token = strtok_single(NULL, ",");
    if (!token) {
        free(parsedRecord);
        return NULL;
    }
    parsedRecord->arrivalTimeMinutes = minutesTimeFromString(token);
    token = strtok_single(NULL, ",");
    token = strtok_single(NULL, ",");
    strcpy(parsedRecord->stopId, token);
    token = strtok_single(NULL, ",");
    sscanf(token, "%d", &(parsedRecord->stopSequence));

    return parsedRecord;
}

struct StopTimeRecord * destinationStopTimeRecordForStopIdAndStartRecord(char * folderName, char * stopId, struct StopTimeRecord * startRecord) {
    char filePath[255];
    memset(filePath, 0, 255);
    strcpy(filePath, folderName);
    strcat(filePath, "/stop_times.txt");
    FILE * destinationRecordSearch = fopen(filePath, "r");
    char buffer[255];
    fgets(buffer, 255, destinationRecordSearch);
    while (!feof(destinationRecordSearch)) {
        fgets(buffer, 255, destinationRecordSearch);
        struct StopTimeRecord * parsedRecord = parseStopTimeRecord(buffer);
        if (parsedRecord) {
            if (strcmp(parsedRecord->tripId, startRecord->tripId) == 0) {
                if (strcmp(parsedRecord->stopId, stopId) == 0) {
                    if (startRecord->stopSequence < parsedRecord->stopSequence) {
                        fclose(destinationRecordSearch);
                        return parsedRecord;
                    }
                }
            }
        }
        free(parsedRecord);
    }
    fclose(destinationRecordSearch);
    return NULL;
}

struct TripStruct * suitableTripForStopsAndStartTime(char * folderName, int startTimeInMinutes, char * startStopId, char * destinationStopId) {
    char filePath[255];
    memset(filePath, 0, 255);
    strcpy(filePath, folderName);
    strcat(filePath, "/stop_times.txt");
    FILE * startRecordSearch = fopen(filePath, "r");
    if (!startRecordSearch) {
        printf("Incorrect input data : stop_times.txt does not exist");
        return NULL;
    }
    char buffer[255];
    fgets(buffer, 255, startRecordSearch);
    int foundFastestFinishTime = -1;
    struct StopTimeRecord * optimalStartTimeRecord = NULL;
    struct StopTimeRecord * optimalDestinationTimeRecord = NULL;
    while (!feof(startRecordSearch)) {
        fgets(buffer, 255, startRecordSearch);
        struct StopTimeRecord * parsedStartRecord = parseStopTimeRecord(buffer);
        if (parsedStartRecord) {
            if (strcmp(parsedStartRecord->stopId, startStopId) == 0) {
                if ((parsedStartRecord->arrivalTimeMinutes >= startTimeInMinutes) &&
                    (parsedStartRecord->arrivalTimeMinutes < startTimeInMinutes + 60)) {
                    struct StopTimeRecord * destinationStopRecord = destinationStopTimeRecordForStopIdAndStartRecord(folderName, destinationStopId, parsedStartRecord);
                    if (destinationStopRecord) {
                        int destinationArrivalTime = destinationStopRecord->arrivalTimeMinutes;
                        if ((foundFastestFinishTime == -1) || (foundFastestFinishTime < destinationArrivalTime)) {
                            foundFastestFinishTime = destinationArrivalTime;
                            free(optimalStartTimeRecord);
                            free(optimalDestinationTimeRecord);
                            optimalStartTimeRecord = parsedStartRecord;
                            optimalDestinationTimeRecord = destinationStopRecord;
                        }
                    }
                }
            }
        }
    }

    if (optimalStartTimeRecord && optimalDestinationTimeRecord) {
        // Form trip data
        struct TripStruct * resultTrip = malloc(sizeof(struct TripStruct));
        strcpy(resultTrip->tripId, optimalStartTimeRecord->tripId);
        resultTrip->startTrip = optimalStartTimeRecord->arrivalTimeMinutes;
        resultTrip->endTrip = optimalDestinationTimeRecord->arrivalTimeMinutes;
        return resultTrip;
    }

    return NULL;
}

#endif

 

TripDataProvider.h

//
//  TripDataProvider.h
//  GTFS
//
//  Created by admin on 9/19/15.
//  Copyright (c) 2015 Stanfy. All rights reserved.
//

#ifndef GTFS_TripDataProvider_h
#define GTFS_TripDataProvider_h

struct RouteInfo {
    char routeId[10];
    char routeName[80];
    int routeType;
} RouteInfo;

void routeIdForTripId(char * folderName, char * tripId, char * routeId) {
    char filePath[255];
    memset(filePath, 0, 255);
    strcpy(filePath, folderName);
    strcat(filePath, "/trips.txt");
    FILE * tripsFile = fopen(filePath, "r");
    char buffer[255];
    fgets(buffer, 255, tripsFile);
    while (!feof(tripsFile)) {
        fgets(buffer, 255, tripsFile);
        char * token = strtok_single(buffer, ",");
        char parsedRouteId[10];
        strcpy(parsedRouteId, token);
        token = strtok_single(NULL, ",");
        token = strtok_single(NULL, ",");
        if (strcmp(token, tripId) == 0) {
            strcpy(routeId, parsedRouteId);
            break;
        }
    }
    fclose(tripsFile);
}

struct RouteInfo * parseRouteInfoFromString(char * routeRecord) {
    struct RouteInfo * parsedRouteInfo = malloc(sizeof(struct RouteInfo));
    char routeShortName[10];
    char routeLongName[80];
    char * token = strtok_single(routeRecord, ",");
    strcpy(parsedRouteInfo->routeId, token);
    token = strtok_single(NULL, ",");
    token = strtok_single(NULL, ",");
    if (token) {
        strcpy(routeShortName, token);
    }
    token = strtok_single(NULL, ",");
    if (token) {
        strcpy(routeLongName, token);
    }
    token = strtok_single(NULL, ",");
    token = strtok_single(NULL, ",");
    sscanf(token, "%d", &(parsedRouteInfo->routeType));
    if (strlen(routeShortName) == 0) {
        strcpy(parsedRouteInfo->routeName, routeLongName);
    } else {
        strcpy(parsedRouteInfo->routeName, routeShortName);
    }
    return parsedRouteInfo;
}

struct RouteInfo * routeInfoByRouteId(char * folderName, char * routeId) {
    char filePath[255];
    memset(filePath, 0, 255);
    strcpy(filePath, folderName);
    strcat(filePath, "/trips.txt");
    FILE * routesFile = fopen(filePath, "r");
    char buffer[255];
    fgets(buffer, 255, routesFile);
    while (!feof(routesFile)) {
        fgets(buffer, 255, routesFile);
        struct RouteInfo * parsedInfo = parseRouteInfoFromString(buffer);
        if (strcmp(parsedInfo->routeId, routeId) == 0) {
            fclose(routesFile);
            return parsedInfo;
        } else {
            free(parsedInfo);
        }
    }
    fclose(routesFile);
    return NULL;
}

void routeTypeStringFromRouteType(int routeType, char * routeTypeString) {
    /*
     0 - Tram, Streetcar, Light rail. Any light rail or street level system within a metropolitan area.
     1 - Subway, Metro. Any underground rail system within a metropolitan area.
     2 - Rail. Used for intercity or long-distance travel.
     3 - Bus. Used for short- and long-distance bus routes.
     4 - Ferry. Used for short- and long-distance boat service.
     5 - Cable car. Used for street-level cable cars where the cable runs beneath the car.
     6 - Gondola, Suspended cable car. Typically used for aerial cable cars where the car is suspended from the cable.
     7 - Funicular. Any rail system designed for steep inclines.
     */
    switch (routeType) {
        case 0:
            strcpy(routeTypeString, "tram");
            break;
        case 1:
            strcpy(routeTypeString, "subway");
            break;
        case 2:
            strcpy(routeTypeString, "rail");
            break;
        case 3:
            strcpy(routeTypeString, "bus");
            break;
        case 4:
            strcpy(routeTypeString, "ferry");
            break;
        case 5:
            strcpy(routeTypeString, "cable car");
            break;
        case 6:
            strcpy(routeTypeString, "gondola");
            break;
        case 7:
            strcpy(routeTypeString, "funicular");
            break;

        default:
            break;
    }
}

#endif

Our team of C programming has access to the latest technology and software and they use it to work on your C Programming assignment and C Programming projects. Thus we ensure excellent grades to all the students who avail our C Programming project help service.

Utils.h

//
//  Header.h
//  GTFS
//
//  Created by admin on 9/17/15.
//  Copyright (c) 2015 Stanfy. All rights reserved.
//

#ifndef GTFS_Utils_h
#define GTFS_Utils_h

char *
strtok_single (char * str, char const * delims)
{
    static char  * src = NULL;
    char  *  p,  * ret = 0;

    if (str != NULL)
        src = str;

    if (src == NULL)
        return NULL;

    if ((p = strpbrk (src, delims)) != NULL) {
        *p  = 0;
        ret = src;
        src = ++p;

    } else if (*src) {
        ret = src;
        src = NULL;
    }

    return ret;
}

void parseLeaveHomeValue(char * leaveHomeValue, int * dayIndex, int * minutesStartTime) {
    char * dayString = strtok_single(leaveHomeValue, " ");
    // Mon Tues Wed Thu Fri Sat Sun
    if (strcmp(dayString, "Mon") == 0) {
        *dayIndex = 0;
    }
    if (strcmp(dayString, "Tues") == 0) {
        *dayIndex = 1;
    }
    if (strcmp(dayString, "Wed") == 0) {
        *dayIndex = 2;
    }
    if (strcmp(dayString, "Thu") == 0) {
        *dayIndex = 3;
    }
    if (strcmp(dayString, "Fri") == 0) {
        *dayIndex = 4;
    }
    if (strcmp(dayString, "Sat") == 0) {
        *dayIndex = 5;
    }
    if (strcmp(dayString, "Sun") == 0) {
        *dayIndex = 6;
    }
    int hours = 0;
    int minutes = 0;
    sscanf(strtok_single(NULL, ""), "%d:%d", &hours, &minutes);
    *minutesStartTime = hours * 60 + minutes;
}

int minutesTimeFromString(char * stringToParse) {
    int hours = 0;
    int minutes = 0;
    int seconds = 0; // Unused
    sscanf(stringToParse, "%d:%d:%d", &hours, &minutes, &seconds);
    return (hours * 60 + minutes);
}

void stringFromMinutes(int minutes, char * timeString) {
    sprintf(timeString, "%d:%d", minutes / 60, minutes % 60);
}

#endif

Our experts provide C programming assignment help with 100% original content. Our codes in C programming homework help is easy to understand. Students can upload their assignment on our website to avail our help with programming homework. help with C programming assignment then I’m sure we can deliver.