Awesome, that seems to work. Thanks so much for your help.
Type: Posts; User: M-S-H
Awesome, that seems to work. Thanks so much for your help.
cool, never mind my edit then.... let me try that.
How so? the first message has a priority of 3 and the second 1, so wouldn't is swap them?
Oh, got it.... so i could just create an if statement to correct this problem? if amount == 2, then another...
yeah, i did, and its still not sorting right.
For example, the two text files:
First:
3I hope this works
Second:
1This program is awesome
yeah, i did, and its still not sorting right.
For example, the two text files:
First:
3I hope this works
Second:
1This program is awesome
I no longer get a segmentation fault, but its not sorting them correctly. Once a priority 3 was printed before a priority 1, then a 2 was first, then 1, then 3; then with everything was sorted...
i did change both to make temp = packages[j];
and j=amount-i should have been j<amount-i, but still no luck
Here's the updated code:
/*************
Michael Hickman
ECE 231
*************/
well i thought this change would make it work, but it didn't
temp = packages[j];
packages[j] = packages[j+1];
packages[j+1] = temp;
yeah, its basically bubble sort...
so what would be a better way?
I'm creating a program that reads text files, each with a priority and message, and then prints them in the correct order. Files with higher priority are printed first, and if they have the same...
Alright, thanks so much for all your help. I really appreciate it.
i fixed the bracket, and it compiled fine, but when i ran it,
a null must have been returned because it displayed "out of memory"
now how do i fix that?
I changed all my code to
/* File: matrix.h */
#ifndef MATRIXh
#define MATRIXh
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#define FORMAT "%8.3lf"
Header File:
/* File: matrix.h */
#ifndef MATRIXh
#define MATRIXh
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#define FORMAT "%8.3lf"
i made all those corrections, but i still get the same compile error:
subscripted value is neither array nor pointer - referring to:
new_matrix.element[i][j] = values[i][j];
as well as a new...
I understand how to set up the matrix, but im now having trouble passing in an 2d array.
The array is set up as:
double one[2][3] = {
{1,2,3},
...
First off, thanks for being patient...im new to programming.
Second the only compile errors refer to
for(j=0; j<rdim; j++)
new_matrix -> element[i][j] = values[i][j]; // does not work...
so i changed my structure to:
typedef struct {
int rowdim, coldim;
double** element;
} matrix;
and then my other code to:
#include "matrix.h"
well how would i keep it as a two dimensional array? Im thinking that I'll have to use a double pointer, but dont know how to set that up.
Alright, so i changed my code to:
#include "matrix.h"
matrix create_empty(int rdim, int cdim)
{
matrix* new_matrix;
new_matrix = malloc(sizeof(matrix));
new_matrix -> rowdim = rdim;...
i read something online about a double pointer being used when working with 2d arrays, but how exactly are they used?
I'm trying to write a program that will create and work with matrices, but im having problems with a pointer to a 2d array.
I created this structure in a header file:
typedef struct {
int ...
LOL,
in my defense, ive only been programming for a month or two
I did add a print statement, but that cause the program to not work. It would print values of t, but it wouldn't print the...
So I found this sudoku solver and I understand the basics, but there are a few things that I quite dont understand, and was wondering if anyone could help.
#include <stdio.h>
int grid[9][9];...