Author Topic: Programing help :(  (Read 6776 times)

0 Members and 1 Guest are viewing this topic.

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Programing help :(
« on: January 23, 2009, 07:33:21 PM »
Code: [Select]
/* write a program that combines the strings ’dir’,
’subdir’, and ’file’ into a full path: /usr/bin/firefox
You will need to dynamically allocate the path array
to an appropriate capacity.
*/

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

int main(void) {
char dir[] = "usr";
char subdir[] = "bin";
char file[] = "firefox";

int pathLength = 17;
char *path; /* string */


path = (char*)malloc(pathLength * sizeof(char));
if (path == NULL) { /* always check for NULL after malloc */
printf("malloc failed: Exiting Program!\n\n");
exit(-1);
}

*path = "/";
strcat(path, dir);
strcat(path, "/");
strcat(path, subdir);
strcat(path, "/");
strcat(path, file);

printf(" %s\n", *path);
/* Free the memory assigned to ’word’ */
free(path);

}

it doesn't like, *path = "/";  but I can't see what's wrong.  I'm dereferencing it and then / should just be placed in the first element of the array.
The compiler gives me a warning of "assignment makes integer from pointer without cast

Even if I remove that line it still doesn't work  :(

« Last Edit: May 28, 2009, 11:43:54 PM by Father_Mike »

ananus

  • Member
Re: C help :(
« Reply #1 on: January 23, 2009, 08:21:05 PM »
1. "s" is an array of chars. 's' is a single char. "shit" is valid, 'shit' isn't.
2. initialize your "strings" with '\0' before appending anything or there'll be garbage from the memory in it. add another '\0' when you're done to make sure it ends at the right place
3. all pointers should be NULL when declared.
4. when you use *path, you derefence the pointer and go to the memory. that means printing a %c, not %s, which is an array of chars, which is a pointer. use path. if you compile with *path, it'll crash.
5. return
6. ident that shit

Code: [Select]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
char dir[] = "usr";
char subdir[] = "bin";
char file[] = "firefox";

int pathLength = 18;
char *path = NULL;

path = (char*) malloc(pathLength * sizeof(char));

if (path == NULL)
{
printf("malloc failed: Exiting Program!\n\n");
exit(-1);
}

*path = '\0';
strcat(path, "/");
strcat(path, dir);
strcat(path, "/");
strcat(path, subdir);
strcat(path, "/");
strcat(path, file);
strcat(path, "\0");

printf("%s\n", path);
free(path);

return 0;
}

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #2 on: January 23, 2009, 08:23:42 PM »
thanks. 


Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #3 on: January 23, 2009, 08:43:44 PM »
Ok got it to work. 

with

Code: [Select]
strcat(path, "/");
how come the first element isn't the null character and the second "/".  Why does the null character get replaced? 

ananus

  • Member
Re: C help :(
« Reply #4 on: January 23, 2009, 08:53:34 PM »
because it marks the end of the char array. '\0' is like saying "it ends rite hurr". when you append more characters, it doesn't end there anymore.

it's been a while since i suffered with c, but i think you can find the answers to these questions with google in 5 minutes.

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #5 on: January 24, 2009, 09:37:20 PM »
Code: [Select]
/* 
Algorithm findPassFail()
This algorithm reads in a text file containing information on a class and determins if students passed or failed. 
It then prints the student number, name, both marks, the overall weighted average, and weither the student passed or failed.

pre:a data file formated as to have the student number (an integer), the student's lastname (a string up to 20
charachters long), the midterm grade (a float between 0 and 100) and the final grade (a float between 0 and 100).

post: It prints the student number, name, both marks, the overall weighted average, and weither the student passed or failed.
return:  void
*/

#include <stdio.h>
#include <string.h>
int main (void) {
char fileName[16];
int studentNum = 0;
char studentName[12];
float studentMark1 = 0;
float studentMark2 = 0;
float studentWeightAv = 0;
char passOrFail[5] = "\0";

FILE *studentFile; // file where student data is kept

printf("Enter the file name \n");
scanf("%s", fileName);

studentFile = fopen(fileName, "r");

if(studentFile == NULL) { //this will be true if there was an
perror("failed to open"); //error such as file not existing
return -1;
}
while(!feof(studentFile)){
fscanf(studentFile, "%i%s%f%f", &studentNum, studentName, &studentMark1, &studentMark2);
studentWeightAv = ((studentMark1 * 0.40)+(studentMark2 * 0.60));

if(studentWeightAv > 50)
strcat(passOrFail, "pass\0");
else
strcat(passOrFail, "fail\0");

if(!feof(studentFile)){
printf("%i    %s    %.2f     %.2f    %.2f      %s \n",
studentNum, studentName, studentMark1, studentMark2, studentWeightAv, passOrFail); // long line broken up
}
};

fclose(studentFile);


return 1;
}

what is going wrong here with

Code: [Select]
if(studentWeightAv > 50)
strcat(passOrFail, "pass\0");
else
strcat(passOrFail, "fail\0");

it prints "pass" on the first line from the file then "passpass" on the second then "passpasspass" then "passpasspassfail" then garbage.

« Last Edit: January 24, 2009, 09:44:57 PM by Father_Mike »

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #6 on: January 24, 2009, 10:07:20 PM »
I'm a fucking idiot


SMH AT ME.   :'( :'( :'( :'(

ananus

  • Member
Re: C help :(
« Reply #7 on: January 24, 2009, 10:50:23 PM »
Code: [Select]
#include <stdio.h>
#include <string.h>
int main (void)
{
char fileName[16];
int studentNum = 0;
char studentName[12];
float studentMark1 = 0;
float studentMark2 = 0;
float studentWeightAv = 0;
char passOrFail[5] = "\0";

fileName[0] = '\0';
studentName[0] = '\0';

FILE *studentFile;

printf("Enter the file name \n");
scanf("%s", fileName);

studentFile = fopen(fileName, "r");

if(studentFile == NULL)
{
perror("failed to open");
return -1;
}
while(!feof(studentFile))
{
fscanf(studentFile, "%i%s%f%f", &studentNum, studentName, &studentMark1, &studentMark2);
studentWeightAv = ((studentMark1 * 0.40)+(studentMark2 * 0.60));

passOrFail[0] = '\0';
if(studentWeightAv > 50)
strcat(passOrFail, "pass\0");
else
strcat(passOrFail, "fail\0");

printf("%i     %s     %.2f     %.2f     %.2f     %s     \n",
studentNum, studentName, studentMark1, studentMark2, studentWeightAv, passOrFail);
}
fclose(studentFile);

return 1;
}

the variables retain their values after the while ends because they're declared outside, so their scope extends the loop's. when you put "pass" in the char array in one execution, in the next one you append "pass" again, so it's "passpass". this is happening because you're not cleaning the variable before you need it again. '\0' at the first position of the char array will "clean" it. it's not really being cleaned but pretend it is.

the if end of file you use inside the while is going to prevent the last line info from being print. once you reach the last line and are inside the loop, it will, in that if, see whether the file has ended or not. since you just read the last line, the file has indeed ended and whatever is inside - the printfs - isn't executed. though you might've wanted to do that.

Flannel Boy

  • classic millennial sex pickle
  • Icon
Re: C help :(
« Reply #8 on: January 24, 2009, 10:54:54 PM »
Stop helping Arvie with his homework. Let him fail and become White Man's sex butler.

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #9 on: January 24, 2009, 11:01:03 PM »
I figured it out before he helped me Malek!  and the first bit of code wasn't really homework it was something we did in the tutorial and I couldn't get it to work and was to embarrassed to ask. 

Anyways thanks ananus.  I figured out to reset the passOrFail with the null character and I can't believe I didn't see what was wrong with it at once.  The last if then was on purpose.  Without it the last line of the file was getting printed off twice.

also is breaking the line up like this good coding?  Is there a way to show that I'm breaking up the like? 

Code: [Select]
printf("%i     %s     %.2f     %.2f     %.2f     %s     \n",
studentNum, studentName, studentMark1, studentMark2, studentWeightAv, passOrFail);
« Last Edit: January 24, 2009, 11:08:46 PM by Father_Mike »

ananus

  • Member
Re: C help :(
« Reply #10 on: January 24, 2009, 11:09:03 PM »
when i print something, i consider it good coding if it prints what i want. i think you wanted the spaces among each column to be even, so it wouldn't be good coding, no. if you just want to separate the data to be visible, it's okay. i think. i've never seen anything about good coding on printing text.

i don't understand the second question.

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #11 on: January 24, 2009, 11:15:20 PM »
O ya I have it all formatted to how i want it to print.  What I mean is in the source code I've dropped half the line because it was to long for the text editor.

This
Code: [Select]
printf("%i     %s     %.2f     %.2f     %.2f     %s     \n",
studentNum, studentName, studentMark1, studentMark2, studentWeightAv, passOrFail);
should be like this

Code: [Select]
printf("%i     %s     %.2f     %.2f     %.2f     %s     \n", studentNum, studentName, studentMark1, studentMark2, studentWeightAv, passOrFail);
In other languages like VB you would have to use a special character to break the line.  I guess it just looks a bit weird not to indicate that it's all one line of code. 

ananus

  • Member
Re: C help :(
« Reply #12 on: January 24, 2009, 11:21:11 PM »
you did the right thing.

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #13 on: January 24, 2009, 11:27:27 PM »
ok thanks. 

recursivelyenumerable

  • you might think that; I couldn't possibly comment
  • Senior Member
Re: C help :(
« Reply #14 on: January 25, 2009, 02:41:47 AM »
Quote
I guess it just looks a bit weird not to indicate that it's all one line of code. 

It's one statement; a statement is the smallest standalone element of code that performs an action, and in C they end with a semicolon.  In VB, one line normally equals one statement, but C doesn't care how you break your lines, except within string literals (where you have to indicate a line continuation with a '\') and for preprocessor commands.  I think of good visual code organization as something like good paragraph and sentence organization in English prose: when possible, it should help clarify your meaning.  I'd probably format your statement as:

Code: [Select]
printf(
    "%i     %s     %.2f     %.2f     %.2f     %s     \n",
    studentNum, studentName, studentMark1, studentMark2, studentWeightAv, passOrFail
);

because (besides that it's just awkwardly long as one line) I think highlighting the correspondence between the format string and arguments is helpful even if they can't actually line up.
QED

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #15 on: January 25, 2009, 11:32:02 AM »
Ok another question

I've heard that void mains are bad, so my program has an int main, even though it only prints something, but then what should I return?  I have return 1 but i don't really know why it should be 1 instead of 0 or any other number.


Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #17 on: January 30, 2009, 10:08:23 PM »
I keep getting memory access problems when I run this and I have no idea why.  It compiles just fine. 

Code: [Select]
/* 
Algorithm takeFindPrintMinMaxMarks()
Description : This algorithm asks the user  how many marks they want to enter, then to enter that many float marks, calls findMinAndMax to determines the smallest and biggest marks then prints them.
Pre: findMinAndMax.h
Post:  The first element of the array to the smallest mark and the second element to the biggest mark. The smallest and biggest marks get printed.   
return:  0
*/

#include <stdio.h>
#include "findMinAndMax.h"

int main (void) {
int i = 0;
int size = 0;
float *numArray;

printf("How many marks would you like to enter?\n");
scanf("%i", size); // takes in the size of the array


numArray = (float*)malloc(size * sizeof(float));
if (numArray == NULL) { /* always check for NULL after malloc */
printf("malloc failed: Exiting Program!\n\n");
exit(-1);
}

for(i; i < size; i++){
scanf("%f", numArray[i]); // takes in the marks
}

findMinAndMax(numArray, size); // calls findMinAndMax function

printf("The lowest grade is %.2f and the highest is %.2f\n", numArray[0], numArray[1]);

free(numArray);

return 0;  // returns 0. 
}

Code: [Select]
/*    *************** findMinAndMax.c ****************
Algorithm findMinAndMax(float numArray[], int size)
Description: This algorithm takes in an array, finds the largest and smallest element and returns the minimum and maximum marks.
Pre: float numArray[] , an array of floats,  int size the size of that array.
Post: float max will be the biggest element.  float min will be the smallest element.  It then sets the first element of the array to the smallest mark and the second element to the biggest mark.
Returns:  numArray by ref. 
*/

void findMinAndMax(float *numArray, int size){
float max = numArray[0];
float min = numArray[0];
int i = 0;

for(i; i < size; i++){
if( numArray[i] > max)
max = numArray[i];
if( numArray[i] < min)
min = numArray[i];
}
numArray[0] = min;
numArray[1] = max;

}

BlueTsunami

  • The Muffin Man
  • Senior Member
Re: C help :(
« Reply #18 on: January 30, 2009, 10:22:02 PM »
Remember to add a function for armateurs
:9

ananus

  • Member
Re: C help :(
« Reply #19 on: January 30, 2009, 10:22:47 PM »
1) didn't initialize the pointer to NULL (wasn't this though)
2) when you scanf, you put the value in the VARIABLE ADDRESS, ie &variable. you forgot the operator in both scanfs.

Code: [Select]
#include <stdio.h>
#include <stdlib.h>

void findMinAndMax(float *numArray, int size)
{
float max = numArray[0];
float min = numArray[0];
int i = 0;

for(i; i < size; i++){
if( numArray[i] > max)
max = numArray[i];
if( numArray[i] < min)
min = numArray[i];
}

numArray[0] = min;
numArray[1] = max;
}

int main ()
{
int i = 0;
int size = 0;
float *numArray = NULL;

printf("How many marks would you like to enter?\n");
scanf("%i", &size); // takes in the size of the array


numArray = (float*)malloc(size * sizeof(float));
if (numArray == NULL) { /* always check for NULL after malloc */
printf("malloc failed: Exiting Program!\n\n");
exit(-1);
}

for(i; i < size; i++)
scanf("%f", &numArray[i]); // takes in the marks

findMinAndMax(numArray, size); // calls findMinAndMax function

printf("The lowest grade is %.2f and the highest is %.2f\n", numArray[0], numArray[1]);

free(numArray);

return 0;  // returns 0. 
}

demi

  • cooler than willco
  • Administrator
Re: C help :(
« Reply #20 on: January 30, 2009, 10:23:46 PM »
Arvie you ever consider starting with HTML and work your way up?
fat

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #21 on: January 30, 2009, 10:26:08 PM »
I should have know that.  Thanks again ananus. 

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #22 on: February 24, 2009, 06:16:48 PM »
You all laughed but I just got the second highest midterm mark in a class of 200!  96.5% bitches


spoiler (click to show/hide)
I got a 59 in clac II  :'(  fucking trig functions!
[close]

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #23 on: April 06, 2009, 07:32:27 PM »
GGGG why isn't this working?
Code: [Select]
FILE *infile;  // File handle for the input file
  char filename[100];  // Input filename 
  TrackingSystem *rTrackingSystem = new TrackingSystem();
  int tempNum = 0;
  char* tempLoc;
 
  printf("Enter the filename:\n");   // Prompt for the filename
  scanf("%s", filename);
  // Open the file
  infile = fopen(filename, "r");
  if( infile == NULL ) {
    perror("An error occured opening the input file");
    return -1;
  }

  while(!feof(infile)){ // checks for end of file
    printf("Test1:\n");
    fscanf(infile, "%i",&tempNum);
printf("%i\n",tempNum);
fscanf(infile, "%s", tempLoc);
//printf("%s\n",tempLoc);
rTrackingSystem->addParcel(tempNum, tempLoc);
printf("Test3:\n");
  } 


it fails at
Code: [Select]
fscanf(infile, "%s", tempLoc);I've used this exact same code before. It worked then and now it doesn't?
« Last Edit: April 06, 2009, 07:33:58 PM by Father_Mike »

Van Cruncheon

  • live mas or die trying
  • Banned
Re: C help :(
« Reply #24 on: April 06, 2009, 07:41:15 PM »
GGGG why isn't this working?
Code: [Select]
FILE *infile;  // File handle for the input file
  char filename[100];  // Input filename 
  TrackingSystem *rTrackingSystem = new TrackingSystem();
  int tempNum = 0;
  char* tempLoc;
 
  printf("Enter the filename:\n");   // Prompt for the filename
  scanf("%s", filename);
  // Open the file
  infile = fopen(filename, "r");
  if( infile == NULL ) {
    perror("An error occured opening the input file");
    return -1;
  }

  while(!feof(infile)){ // checks for end of file
    printf("Test1:\n");
    fscanf(infile, "%i",&tempNum);
printf("%i\n",tempNum);
fscanf(infile, "%s", tempLoc);
//printf("%s\n",tempLoc);
rTrackingSystem->addParcel(tempNum, tempLoc);
printf("Test3:\n");
  } 


it fails at
Code: [Select]
fscanf(infile, "%s", tempLoc);I've used this exact same code before. It worked then and now it doesn't?

Quote from: ananus
2) when you scanf, you put the value in the VARIABLE ADDRESS, ie &variable. you forgot the operator in both scanfs.

JESUS

spoiler (click to show/hide)
fscanf(infile, "%s", &tempLoc);
[close]
duc

Van Cruncheon

  • live mas or die trying
  • Banned
Re: C help :(
« Reply #25 on: April 06, 2009, 07:42:28 PM »
hall of shame this
duc

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #26 on: April 06, 2009, 07:43:36 PM »
I literally just copied the code from an old working assignment though  :'( :'( :'(

It worked then!

No need for the hall of shame.  I've already spent an hour trying to figure this out.  I fucking suck  :'(

EDIT:  didn't work drinky. 
« Last Edit: April 06, 2009, 07:45:46 PM by Father_Mike »

Van Cruncheon

  • live mas or die trying
  • Banned
Re: C help :(
« Reply #27 on: April 06, 2009, 07:50:54 PM »
then the issue is ALSO somewhere else, like in

scanf("%s", filename);

which should be scanf("%s", &filename); ??
duc

Van Cruncheon

  • live mas or die trying
  • Banned
Re: C help :(
« Reply #28 on: April 06, 2009, 07:52:03 PM »
& = address of.

* = reference to.

just fyi
duc

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #29 on: April 06, 2009, 07:58:56 PM »
I don't think that's right

for fscanf

s   String of characters. This will read subsequent characters until a whitespace is found (whitespace characters are considered to be blank, newline and tab).   char *

fscanf (pFile, "%s", str);


http://www.cplusplus.com/reference/clibrary/cstdio/fscanf.html

tempLoc is already a reference to a char so it's the right type of argument

The only thing I can think of is now I'm working in C++ where before it was just C, but I doubt that would be the problem. 

recursivelyenumerable

  • you might think that; I couldn't possibly comment
  • Senior Member
Re: C help :(
« Reply #30 on: April 06, 2009, 08:40:25 PM »
it's been a while since I did C, but I think you have to allocate memory for the buffer you're fscanfing into before you fscanf into it, don't you?  I don't think just declaring a char* is enough.

p.s. fscanfing (two syllables) is pretty fun to say
QED

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #31 on: April 06, 2009, 08:46:06 PM »
ya when I switched it to tempLoc[100] it worked but I think allocating it would look nicer.  I swear I didn't have to do that on anouther assignment though. 

Now I have a problem in this mess

Code: [Select]
BSTNode *BST::insert(BSTNode *v, Parcel *el) {
/**** IMPLEMENT THIS METHOD ****/
printf("Test1:\n");
if (v != NULL && v->getParcel() == el) //there is a node and it already has nData
return NULL;
else if (v != NULL && el->getNumber() < v->getParcel()->getNumber() && v->getLeftChild() != NULL)
return insert(v->getLeftChild(), el);
else if (v != NULL && el->getNumber() > v->getParcel()->getNumber() && v->getRightChild() != NULL)
return insert(v->getRightChild(), el);
else{ //either rNode is NULL or we should insert new node as a left or right child
BSTNode* rNew;
rNew = new BSTNode(el, NULL, NULL);

if (v = NULL) {
printf("Test1:\n");
v = rNew;
}
else if (el->getNumber() < v->getParcel()->getNumber())
v->setLeftChild(rNew);
else
v->setRightChild(rNew);
printf("Test1:\n");
return rNew;
}

}

 :'(  It's my last assignment of the year and I just want it to be done  :'( :'( :'( :'(

I wish error codes for memory violation were more helpful. 
« Last Edit: April 06, 2009, 08:47:58 PM by Father_Mike »

recursivelyenumerable

  • you might think that; I couldn't possibly comment
  • Senior Member
Re: C help :(
« Reply #32 on: April 06, 2009, 08:46:35 PM »
and yeah, prole is wrong about the need for & here.  jumping to conclusions lulz
QED

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #33 on: April 06, 2009, 08:52:18 PM »
Code: [Select]
BSTNode* rNew;
rNew = new BSTNode(el, NULL, NULL);

if (v = NULL) {
printf("Test1:\n");
v = rNew;
:lol :lol :lol

wait that's not funny.  I think that's what I want.   :'(

FUCKING "=="!!!!!!!!!!!!!!
« Last Edit: April 06, 2009, 09:00:22 PM by Father_Mike »

Van Cruncheon

  • live mas or die trying
  • Banned
Re: C help :(
« Reply #34 on: April 06, 2009, 10:40:17 PM »
and yeah, prole is wrong about the need for & here.  jumping to conclusions lulz

come on, assuming arvie can't read is usually safe
duc

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #35 on: April 06, 2009, 10:47:21 PM »
I can't get this to work.   :'(  I've been doing all assignments on the last day and getting 95's but not this time.   :'( :'( :'(

Loki

  • Member
Re: C help :(
« Reply #36 on: April 07, 2009, 01:41:20 AM »
FM annihilated...

I nearly spit out my drink. :lol

Reading these topics makes me remember why I dropped CS as a major after a few semesters: te-di-um.  Loved the problem solving aspects, hated the syntax.

recursivelyenumerable

  • you might think that; I couldn't possibly comment
  • Senior Member
Re: C help :(
« Reply #37 on: April 07, 2009, 02:07:33 AM »
Should've used a language with barely any syntax.

I think the == for Boolean equality test, = for assignment convention is idiotic, by the way.  It exists only to generate bugs, but somehow it became the standard, possibly through industrial sabotage.
« Last Edit: April 07, 2009, 02:10:56 AM by recursivelyenumerable »
QED

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #38 on: April 26, 2009, 10:52:05 PM »
My laptop sucks.  I just tried to run a program that calculates the nth line of pascals triangle that is O(n^2).  It's been running for 20 mins and hasn't finished yet.   :'(

Ecrofirt

  • Heavy Metal Jesus
  • Senior Member
Re: C help :(
« Reply #39 on: April 26, 2009, 11:26:19 PM »
Eh, it's all good.

I've never quite figured out exactly what & and | mean, as opposed to && and ||.
8=D

recursivelyenumerable

  • you might think that; I couldn't possibly comment
  • Senior Member
Re: C help :(
« Reply #40 on: April 27, 2009, 12:54:09 AM »
uh you shouldn't be using the O(n^2) version, that's what the -O1 switch is for (or in Visual Studio Project -> Properties -> Performance Settings and select O(1) in the Asymptotic Complexity listbox)
QED

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #41 on: April 27, 2009, 01:01:20 AM »
The point was to run an O(2^n) and then a O(n^2) to see the time difference though.  In fact it was out of the CTM textbook you recommended to me which I am just now getting to read  :-\.

Mozart is annoying as hell btw  :'(. 
« Last Edit: April 27, 2009, 01:07:07 AM by Father_Mike »

recursivelyenumerable

  • you might think that; I couldn't possibly comment
  • Senior Member
Re: C help :(
« Reply #42 on: April 27, 2009, 01:19:19 AM »
ooh, that's awesome that you're reading it, I shouldn't be snarky then

but just so you know, I was making a funny
QED

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #43 on: May 13, 2009, 11:27:28 PM »
how the hell do I do this?

(r) Assume that the file class list.txt contains data of the following format:
Fname,Lname,Student number,Major,Mark
Write a shell command to:
i. Sort the file alphabetically by the student's last name.
ii. Sort the file in reverse alphabetical order by the student's last name.
iii. Sort the file in order from lowest to highest mark.
iv. Show only the second and fourth columns of the file.

tiesto

  • ルカルカ★ナイトフィーバー
  • Senior Member
Re: C help :(
« Reply #44 on: May 14, 2009, 10:36:36 AM »
how the hell do I do this?

(r) Assume that the file class list.txt contains data of the following format:
Fname,Lname,Student number,Major,Mark
Write a shell command to:
i. Sort the file alphabetically by the student's last name.
ii. Sort the file in reverse alphabetical order by the student's last name.
iii. Sort the file in order from lowest to highest mark.
iv. Show only the second and fourth columns of the file.

2 dimensional arrays and strcmp?
^_^

Tauntaun

  • I'm cute, you should be too.
  • Senior Member
Re: C help :(
« Reply #45 on: May 14, 2009, 11:02:52 AM »


This guy looks like he has wet hands. 

spoiler (click to show/hide)
:tauntaun
[close]
:)

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #46 on: May 14, 2009, 08:20:44 PM »
how the hell do I do this?

(r) Assume that the file class list.txt contains data of the following format:
Fname,Lname,Student number,Major,Mark
Write a shell command to:
i. Sort the file alphabetically by the student's last name.
ii. Sort the file in reverse alphabetical order by the student's last name.
iii. Sort the file in order from lowest to highest mark.
iv. Show only the second and fourth columns of the file.

2 dimensional arrays and strcmp?

I'm suppose to use built in unix commands.  Sorry I should have said that.  :-[ This is no longer just a c thread. 

edit:  figured it out.  It sucks not knowing unix and just being thrown into it. 
« Last Edit: May 14, 2009, 11:53:59 PM by Father_Mike »

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: C help :(
« Reply #47 on: May 16, 2009, 04:11:19 PM »
Code: [Select]
void Print_Reverse(char* str) {
char* temp;
      int iEnd = 0;
      int iFront = 0;
      temp[0] = str[iEnd];
     
      while(temp[0] != '\0'){    /* finds string size with a loop */
  temp[0] = str[iEnd]; /* didn't know if this counts as using it as a varable */
  iEnd++;
      };
     
      while(iEnd > iFront){   
  iEnd--; /* goes back on chacter so it does not print the null character */
  temp[0] = str[iEnd];
  str[iEnd] = str[iFront];
  str[iFront] = temp[0];
  iFront++;
      }
      printf("%s\n", str); */
}

Why is this segfaulting on me  :'(
« Last Edit: May 16, 2009, 04:27:00 PM by Father_Mike »

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: Programing help :(
« Reply #48 on: May 28, 2009, 11:44:18 PM »
I just wrote a 1000 line bash script fml

Bocsius

  • is calmer than you are
  • Senior Member
Re: Programing help :(
« Reply #49 on: May 29, 2009, 12:03:05 AM »
I just wrote a 1000 line bash script fml


There's no way it works.

(in before yaere is th)

Madrun Badrun

  • twin-anused mascot
  • Senior Member
Re: Programing help :(
« Reply #50 on: May 29, 2009, 12:57:36 AM »
It does.  It is the fucking ugliest thing ever but it works.  Bash is a foul language.