Adak 419 Nearly a Posting Virtuoso

In a previous version, i may have equaled the count of the numbers entered, but not now.

Now you want i=0;i<count;i++ and %d, array for the for and print statements, respectively.

Technically, the top for statement should be "this < count-1". Why? Because next is always one element higher than "this". So "this", doesn't need to go to the end of the array. In reality, it just loops one more time, doing nothing, because "next" has already reached the highest element in the array, and won't even start looping outside the array. So it's fine, but know that, if you're asked by some smarty pants teacher. ;)

Adak 419 Nearly a Posting Virtuoso

Selection sort does NOT compare every element, with every other element, every time through the loop - you misunderstood the algorithm.

Selection sort is always a step better than bubble sort, in my tests on both random and real life data.

Bubble sort and Gnome sort, are the slowest non-joke sorting algorithms, that I've ever seen. There's nothing to recommend either one of them, frankly.

This is a simplified version of Selection sort, and note how the j variable starts with i+1, on every pass through the inner loop:

for(i=0;i<MAX-1;i++) {
  for(j=i+1;j<MAX;j++) {
    if(a[i] > a[j]) {
      temp = a[i];
      a[i] = a[j];
      a[j] = temp;
    }
  }
}

I like this version because it's easy to memorize, and use. It doesn't select anything, so I call it Easy or EZ sort, but it's based on Selection sort. Compare it with your version.

Adak 419 Nearly a Posting Virtuoso

Please forget about the previous problem and the code that solved it - it puts the focus on something that is not the NOW problem. That's what to focus on.

As you stated the problem, the answer is there is a HUGE number of n, that can't be exactly equaled by any combination of 6, 9, and 20. Somehow, the problem has to limit the size of n.

Explain that, and then we can talk turkey, er chicken, about this problem. ;)

Adak 419 Nearly a Posting Virtuoso

I would have guessed that "things don't work in a proper way". Way too vague, however. :(

First, post your code with CODE TAGS around it, so it doesn't look like what the dog threw up last week, and second, post the errors - the SPECIFIC ERRORS, that you are experiencing with the program.

Respect the fact that people are giving you free advice, and don't waste their time being coy about the details. Code lives or dies based on the details.

Try again, please! ;)

Adak 419 Nearly a Posting Virtuoso

Because you have it set to return Boolean values (0 or 1), you can use a construct like this:

if(is_prime(number))
  printf("\n%d is prime", number);
else
  printf("\n%d is not a prime number", number);

if(is_prime(number))
  printf("\n%d is prime", number); 
else 
  printf("\n%d is not a prime number", number);

The return from a function is normally "caught" by a variable, like so:
myVariable = is_prime(number);

if(myVariable == 1)
  etc.
else
  etc.

If you don't "catch" the returning value (and always do so with the right data type, of course), then the return value is lost. (when is determined by the OS)

The "golden rule" with returned values is:
"Don't ever return the address (a pointer), to a local variable"!

Since the local variable is marked as no longer valid, the address may or may not, be valid, and leads to bugs that are VERY hard to sort out, later.

Adak 419 Nearly a Posting Virtuoso

You have to work out the simplest, clearest, and most efficient way to program.

#include <stdio.h>

#define SIZE 20

int main(void)
{
  int i = 0, n = i;
  int array[SIZE];
  int sum = 0;
  
  while (scanf("%d", &array[i]) !=0 ){
    printf("Entered Integer number %d: was %d\n", i, array[i]);
    sum += array[i];  //<----- add this line
    i++;
  }  
 
/* Right here, i equals the number of int's you have put into the array, so
the for loop below could be simplified n=0;n<=i;n++. However it shows an
even simpler and more efficient answer - put the sum into the same while()
loop as the entry (why the hell not?), and forget this second loop,
completely - it's useless. 
*/ 


//Ditch this loop like a bad habit :(
 for (i = 0; scanf("%d", &array[i]) == 0; i++){
   sum = sum +  array[i];
   printf( "The sum is: %d\n", sum);
   return (sum); //??? you're joking right?
  }      


  printf("The sum was %d", sum);      
  return 0;
}
Adak 419 Nearly a Posting Virtuoso

Setting your buffering for stdout depends on:

1) Your OS. It may set it as buffered or unbuffered. Unbuffered is preferred.
2) Your compiler Should have an "environmental" variable for this

3) You may be able to explicitly set or override it by:
a) putting a \n a the end of each printf(" <something> \n");
b: using setbuff();

#include <stdio.h>

/* BUFSIZ is defined in stdio.h */
char outbuf[BUFSIZ];  //for setting buffered output only

int main(void)
{
   /* attach a buffer to the standard output stream */
   setbuf(stdout, outbuf);
[B]   setbuf(stdout, NULL); //removes buffering from stdout[/B]

   /* put some characters into the buffer */
   puts("This is a test of buffered output.\n\n");
   puts("This output will go into outbuf\n");
   puts("and won't appear until the buffer\n");
   puts("fills up or we flush the stream.\n");

   /* flush the output buffer */
   fflush(stdout);

   return 0;
}

The above shows how to set, reset, and test buffering for stdout, for dos & Windows to XP.

If you're using Linux, ask in your Linux distro's forum or the general Linux forum. They're quite knowledgeable.

Adak 419 Nearly a Posting Virtuoso

You forgot the i++ in the first line of the for loop.

Adak 419 Nearly a Posting Virtuoso

The first problem I found is the while loop in main(). It has some nice bits of logic, but the overall program flow is flawed.


This is your while loop, with just a few changes:
1) The newline char is now removed from line[], right away
2) The FILE pointer you called "file", I changed immediately to "fp". Although C is case sensitive, I won't put up with that kind of name confusion.
3) I added the int variable j, and moved i and j declarations, to the top of the function.

The problem is that word[] was being sent to Palindrome(), and word[] had only one valid letter in it.

while((fgets(line,MAX,fp))){					//for some reason, this produces
		//int i;										//line of second mixed with first
		printf("%s\n",line);
		fflush(stdout);
		for(i = 0; line[i] != '\n'; i++){
			c = line[i];  //why assign an int, a char from the array of line?
      //remove the newline char:
      j = strlen(line);
      if((line[j-1])=='\n')
        line[j-1]='\0';

			if(isalpha(c)){
				word[wl] = c;
				wl++;
			}else{
				if(wl>0){
					word[wl] = '\0';
					printf("%s",word);			//for testing
					fflush(stdout);
					words++;
				}else{
					continue;					//if it's a single non-alpha
				}								//it's not a word
			}

			if(isPalindrome(word) == 0){ //not good here - word holds trash atm.
				new = (struct pal*)malloc(sizeof(struct pal));
				new->word = word;
				new->count = 1;
				if(front->count == -1){
					front = new;
				}else{
					new->next = front;
					front = new;
				}
			}

			wl = 0; //each letter then gets stuffed into word[0]
		}
	}

So Palindrome() is being called WAY too soon. …

mi.mac.rules commented: Great Advice! +1
Adak 419 Nearly a Posting Virtuoso

Dude, if you want help on the forum, then post your code on the forum. I went to your link and all I could do was get advertising and crap. Your file is apparently there, but you can't d/l it.

Get real if you want help.

Adak 419 Nearly a Posting Virtuoso

Multiple column sorting sounds like multi-key sorting, where the column totals, are the keys. This is something YOU must verify. Only you know the instructor who gave you the assignment, and have the class notes, contacts, etc.

Sounds like each key is ranked by it's priority, same as always.

Please Google that term and check exactly what the instructor has asked you to do, however.

Sometimes the words are slightly unclear, so an example is always best to show a clear meaning. That is something YOU have to give US, and show us what you've done to complete this assignment.

Adak 419 Nearly a Posting Virtuoso

Just checked, and there's a TON of sites on this topic, on Google. No code here, but this applet shows the actual "inner workings". Once you read up on it pretty good, go here and see the bits fly:
http://www.ecs.umass.edu/ece/koren/arith/simulator/Booth/

Adak 419 Nearly a Posting Virtuoso

I prefer using fgets(charArrayName, sizeof(charArrayName), stdin); with
sscanf("%c", &charVariable);, generally.

In this case, it's no better. I seldom use getchar() except to pull newlines off the input stream to clean it up, so I'm not the best person to ask this.

I tend to use what's simple, and works, and let the "right" and "wrong" take care of themselves.

You're very welcome!

Adak 419 Nearly a Posting Virtuoso

guess and tries should be int's - you'll never have .23 of either! ;)

Try adding a lo, mid, and hi variable. Then, when the guess is too high, bring down the hi variable to your current guess-1.

When your guess is too low, bring up your lo to your current guess+1.

mid will always start each loop with: mid = (lo+hi)/2

Adak 419 Nearly a Posting Virtuoso

May I suggest something more do-able? This just seems WAY over your programming level.

Nevertheless - strtok() is the function most commonly used to "burst" words into a 2D char array, word by word.

I can't say this is anything but rough code, but this will burst up to 120 words from a file, onto your screen. Changing puts() to fputs(filePointer, etc.), will write each word to a file. You need a file pointer made valid by fopen, using "w" mode, instead of "r", as you see in this program. So you'll need to add that, before you can write any words to the file.

Ask back if you have any questions, but I really hope you take on a simpler project.

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

#define SIZE 120

int main ()
{

  FILE* fp;
  char str[SIZE][SIZE] = {{'\0'}};
  char* filename = "words.txt";
  char test[SIZE];
  char *ptr;
  int i, len;
  int r=0;
  printf("\n\n");

  if (!(fp = fopen(filename,"r"))) { 
    printf("\nCannot open %s for output.\n",filename);
    return 1;
  }
  ptr = NULL;
  len = r = 0;
  while(fgets(test,SIZE,fp) != NULL) {
    ptr=strtok(test, " ");  //handles the first word in the buffer
    if(ptr) {
      strcpy(str[r], ptr);
      len=strlen(str[r]);
      if(str[r][len-1]=='\n')
        str[r][len-1]='\0';
      ++r;
    } 
    while(ptr) {
      ptr = strtok(NULL, " ");  //handles subsequent words in the buffer
      if(ptr) {
        strcpy(str[r], ptr);
        len=strlen(str[r]);
        if(str[r][len-1]=='\n')
          str[r][len-1]='\0';
        ++r;
      }
    }
  }
  i=0;
  while(i<r) {                 //displays one word per row, on stdout.
    if(i % 20 == 0 && i) { 
      puts("\n\n        press enter to display …
Adak 419 Nearly a Posting Virtuoso

Your input stream is still holding the newline char. Remove it by adding this:

(void) getchar();

After each time you're looking for a char input (getchar or scanf(%c)).

fflush(stdin) is non-standard, and generally doesn't work, because stdin is an input stream, not an output stream.

And Welcome to the forum, Caeon! ;)

Adak 419 Nearly a Posting Virtuoso

I believe you're making it hard for yourself. Just:

1) Sort the data points for each row in the 2D array.
2) Print the stem, the | and the columns of data from that stems row of the array.

And you're done. Don't use Rube Goldberg logic - simplicity leads to clarity, leads to a quick and bug free program. (If there can be such a thing! ;) )

Adak 419 Nearly a Posting Virtuoso

I don't personally find Bubble sort to be intuitive. This is intuitive to me, simpler, and on random numbers, slightly quicker than Bubble sort:

for(i=0;i<Max-1;i++) {
  for(j=i+1;j<Max;j++) {
    if(a[i] > a[j]) {
      temp = a[i];
      a[i] = a[j];
      a[j] = temp;
    }
  }
}

It's like Selection sort, without the "selection". It's easy to memorize, and faster than quicksort for arrays with less than 100 values.

I've called this algorithm Bubble sort and Selection sort, but it's really a simplified blend of the two. So now I call it Easy sort.

"A rose by any other name..."

Insertion sort is the fastest sorting algorithm for less than 100 values, (especially when the values are already partly sorted), but it's not as easy to memorize. I use it to optimize Quicksort when the sub-arrays are small. Very helpful.

Adak 419 Nearly a Posting Virtuoso

I use Turbo C/C++ a LOT, and it supports //comments, with either the C or C++ compiler.

My version is 1.01

Your install may have become corrupted. Look for the Turbo C/C++ version, NOT the Turbo C version (which was earlier, and had significant bugs).

Turbo C/C++ 1.01 is good, but it doesn't have the newer features. If your teacher/school allows it, moving up to Visual Express or Code::Blocks would be a big step up. Both are free.

I don't do much of anything with bubble sort, but I believe this is right. Test it for yourself, however:

void bubbleSort(int A[]) {   
  int i, n, swapped;
  n = MAX;
  do {
    swapped = 0;
    for(i =0; i < n; i++) {  
      if(A[i] > A[i + 1 ]) {
        swap(A, i, i + 1);
        swapped = 1;
      }
    } //Look, these comments work fine!
    --n;
  }while(swapped);
}

void swap(int A[], int l, int m) {     //more comments!
  int temp;
  temp = A[l];
  A[l] = A[m];
  A[m] = temp;
}
Adak 419 Nearly a Posting Virtuoso

In this code:

void DollarsToYen ( float Dollars[], float Yen[], int count )
{
    int j;
    for (; j < count; j++)
    Yen = Dollars * DOLLARS_TO_YEN;
    printf("","The conversion of $ to y is %10.2f\n",Yen);

}

Dollars is an array, and you shouldn't be trying to multiply that address at all. You want:

Yen = Dollars[j] * DOLLARS_TO_YEN;

But you need to initialize j = 0, in the for loop.

Adak 419 Nearly a Posting Virtuoso

Include string.h header file, and use strstr() to check each line of text, in the char array "line".

For each line, you may need to have two checks, one for each word, depending on the specifics of your search.

If the words are found, print the line array. Note that strstr() returns a pointer, and that pointer will have the address of the found word (if it's there), or NULL otherwise.

Carry on!

Adak 419 Nearly a Posting Virtuoso

I'm not sure if you want to separate numbers FROM letters, or numbers AND letters, but:

if FROM:
Numbers have lower ascii values than any letter, so any char less than 'A' can't be a letter.

if AND:
Remember that a pointer or index can "walk" a string array, or a block of memory, and thus individually allow your program to work with any single char you want to work with. In essence, they are already separated, since each one can be dealt with individually.

If you have more questions, please be specific, show us your attempt at solving this problem, and give an example of what you want, as well as a description.

Specifics are VERY important, in programming.

Adak 419 Nearly a Posting Virtuoso

<< I've been ninja posted >> ;)

Adak 419 Nearly a Posting Virtuoso

Algoritmus, your code is OK.

Understand that Ancient Dragon is being technically correct and please don't:

1) Get upset. Get comfortable in your skin, and "thicken" it. Don't feel threatened by a critique of your code or pseudo code. That's what we do here!

2) Please stop making excuses. "It's a simple function", "it's pseudo code". Neither invalidates the critique made.

No one is at the top of their form all the time, no one is right 100% of the time. If the creator of C can make errors in his book on C, you and I, and AD, can (and will), make errors as well.

It doesn't mean you're not a good person, or a good programmer. Just PLEASE don't make the mistake that sends the guys away from Mars, heading for Jupiter instead. That's all I ask. << C'mon smile >> ;) ;)

Adak 419 Nearly a Posting Virtuoso

The simplest way to avoid this, on this forum, is to stay AWAY from "NIGHTS". He's a pointer fan, big time! ;)

Seriously, use indeces (aka indexes), instead of pointers. Let C handle the change from index to pointer value.

Are you trying to add up the whole array?

Adak 419 Nearly a Posting Virtuoso

You haven't given enough info to answer that question - there are many different ways to make a database.

For the simplest - a "flat file", you have one or more data files, that are accessed by your program, as needed. If the amount of data is quite small, it may be loaded into memory, but probably, at least parts of it, will be accessed through files.

Any way you go, you'll need to have functions to search, sort, display, add and delete (usually just a zero out of a name or ID number and name), or re-size (compress), the data. The search and sort need to handle multiple and single entries, (group searches), and sort by multiple keys. (via pointer or index arrays, no data is really sorted, it just looks that way).

Some types might include:
1) "roll your own". ;)
2) MS Access (full or just a helper) for Access
3) MySql lite
4) MySql
5) Oracle
6) IBM

I'm sure there are others. In C, you usually use structs to group the different characteristics (members and fields), of the record. Data is handled via binary mode reads and writes, of those records and/or fields.

BEFORE you post back for further info, post up YOUR program and let's talk specifics about that. Databases are a BIG topic, and unsuited for long forum posts. There is a lot of info available on the net.

Adak 419 Nearly a Posting Virtuoso

It could be just as simple as:

for(i=0;i<LinesOnYourScreen;i++)
  putchar('\n');

There is no magic command to clear a screen that I know of. You can either write out a space (that is, a blank space with the current background color), or you can output newlines.

You should use unbuffered output to the screen, and something inherently faster than printf().

Adak 419 Nearly a Posting Virtuoso

<nevermind>

Adak 419 Nearly a Posting Virtuoso

The shift key shows no output, by itself, so it has no ASCII code value. If the shift key is depressed, the OTHER keys will have a different ASCII value, but the shift key itself, doesn't need one.

There is a "shift in" and "shift out" at ASCII 14 and 15, but that is legacy stuff from telegraph days, iirc.

Adak 419 Nearly a Posting Virtuoso

You make my point, however Night. You made an error in your code, just trying to display it.

You might need that kind of control in your work, and I agree that indeces become pointers "under the hood" of C arrays - but whenever a simple index will suffice, that's clearly the way I want to work with arrays.

I assure you, I can be VERY creative with errors when working with a complex pointer program. Oh yes! ;)

Adak 419 Nearly a Posting Virtuoso

Pointers do kick butt!

This is against my religion, however:

((int *)(Array + (sizeof(int) * (1 + (2 * ROWMAX)))))[0] = 69;

I haven't found it's set of horns or pitchfork, just yet - but I'm still looking! ;)

I like mallocing arrays however. That's an important skill to practice from time to time. Especially 2 and 3 dimension arrays.

In general, I'll use indexing for array logic, though. It's cleaner and clearer, imo.

Adak 419 Nearly a Posting Virtuoso

No. C is definitely row and then column order.

Cartesian is given as x,y, where x is the horizontal value, and y is the vertical value. So x = C's column, and y = C's row.

C has some functions that directly correspond to Cartesian coordinates, though. I'm thinking of gotoxy(x,y)

Adak 419 Nearly a Posting Virtuoso

Yes. In C, it's array[row][column].

Adak 419 Nearly a Posting Virtuoso

Maybe it's the zero at the end of one of the words, maybe you don't understand strtok() as well as you thought, maybe it's something entirely simple and different.

Maybe tomorrow or next month, you'll slap your head and say "Oh, of course!". Who knows.

When you are stuck with something that's not working - and you've done everything you can think of - it's time to do it another way. There's nothing magical about strtok().

Adak 419 Nearly a Posting Virtuoso

Not to interrupt your focus on strtok, but you could "roll your own" on such a simple task, in half the time, and half the trouble.

start at the first char of the string
in a loop, "walk" through the string, until you find a comma, assigning a
small char buffer, the value of each letter as you walk the string.

When you reach the comma, set it's index number to an offset variable, and put
an end of string char onto your small char buffer, if it didn't have one already.

Now move each letter in the string array, down by the offset variable value, within the string. I call it "boogie left". ;)

If the comma was at index 15, then string[i-offset] = string, in a loop.

And you're ready to process your small char buffer, and repeat this, in your loop.

It's harder to describe it than it is to code it. For small and moderate strings, it's plenty fast, if not the most efficient answer.

Adak 419 Nearly a Posting Virtuoso

Now I think I see what you're question is:

Try running this:

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

int main() {
  int i, unique; 
  char str[]="developer,developer0,developer";
  char *pstr;
  printf("\n\n original string: %s \n", str);
  pstr = strtok(str, ",");
  printf("\n  pointer: %s \n", pstr);
  printf("\n string[]: %s \n", str);


  while(1) {
    pstr = strtok(NULL, ",");
    if(!pstr)
      break;
    printf("\n  pointer: %s \n", pstr);
    printf("\n string[]: %s \n", str);
  }
  printf("\nFinal string prints as: %s \n", str);
  printf("\nBut the final string has visible char's of: \n");
  for(i=0;i<sizeof(str);i++)
    putchar(str[i]);
  
  printf("\n\n\t\t\t     press enter when ready");

  i = getchar(); ++i;
  return 0;
}
Adak 419 Nearly a Posting Virtuoso

So, if you can read, what's the problem?

The answer is right in front of you. ;)

Adak 419 Nearly a Posting Virtuoso

I took the data you posted, and put it into a file named "temps.txt" for the program to access.

If you have any questions, please ask away. I haven't checked that this program is accurate, so by all means, test it out for yourself.

#include <stdio.h>
#include <stdlib.h>  //for exit()
#define SIZE 310     //31 * 10 the size of our array of structs


/* prototype and declare a struct named "data1" */
typedef struct
{
int site_id; /* id number of the site */
int date; /* the day of the month written as dd */
int wind; /* the wind speed in knots */
int degrees; /* temp in celcius */
}data1;   


/* input function prototype */
int input(data1 *data, int *topWindSite, int *topTempSite);  

int main(void) {
  int i, count, topWindSite, topTempSite;
  char choice[3];

//make array of structs of type "data1", named data[]. 
//It will hold SIZE (310) structs
  data1 data[SIZE];  
  topWindSite = topTempSite = 0;
//call input() with data (just an address now), and two int variable addresses
//return from input() will be the number of records in the file - count.
  count = input(data, &topWindSite, &topTempSite);
  
  printf("\n\nThere are %d records", count);
  printf("\n Site with the highest average wind speed: %d", topWindSite);
  printf("\n Site with the greatest temperature range: %d", topTempSite);

  printf("\n View the records? [y/n]: ");
  fgets(choice, sizeof(choice), stdin);
  if(choice[0]=='y' || choice[0]=='Y') {
    for(i=0;i<count;i++) {
      printf("\n%4d  %2d  %2d  %2d",\
      data[i].site_id, data[i].date, data[i].wind, data[i].degrees);
    }
  }
  printf("\n\n\t\t\t    press enter when ready");
  i=getchar(); 
  return 0;
}
int …
Adak 419 Nearly a Posting Virtuoso

Yes, but only in a very limited way. You can use text functions in the console window. You can go into graphics mode, with the limited drivers that TC had, from back in the DOS days. Those still work.

I use TC for small text window programs - little puzzles and questions that you commonly see on the forum, here.

What you can't do:

1) Anything requiring more than about 400Kb. So all arrays sizes are limited, especially for structs and doubles. One program I wrote, using a small struct, is limited to just 700 max in the array of structs. For int's, it's 25,000 max.

2) Use the Windows API. TC has it's own extensions (mostly through supporting the header file "conio.h", so you don't need the Windows API for a lot of simple things - but that's not the same as having access to the whole Windows API, by a long stretch.

It's simpler, but a lot less complete.

So unless you are required to use it by your instructor, you should NOT start with it. With Windows 7, it's even worse to try and run Turbo C programs, requiring a special virtual machine. (Windows XP provides that virtual machine automatically for 16 bit programs.).

Adak 419 Nearly a Posting Virtuoso

Well it shouldn't be hard to shorten it with a recursive program. ;)

This, from a guy with perhaps the longest iterative program (very visual despite just a text window).

The thing you have to know is that the recursive function uses a "dance". The "from" needle, and the "to" needle, move back and forth, like crazy.

Then there is the number 6. Six shoe horns beautifully into this function, because the needles have numbers of 1, 2, or 3. So six minus the from needle, minus the to needle of the last move -- Well, hot damn! it gives you the number of the new "from" needle. << and that's some shit! >>

Since this "dance" works, it means that every call to the (I'll call it Hanoi function), has a double recursive call to itself.

Now you know why I wrote my version, iteratively. ;)

In pseudo code it looks like this:

i=1, j=2
Hanoi(number of disks, i, j, and moveNum) { //all int's
  moveNum++
  Hanoi(n - 1, i, 6 - i - j, moveNum)
  print moveNum. move i to j
  if(moveNum mod 4 == 0) 
    print newline
  Hanoi(n - 1, 6 - i - j, j, moveNum)
}

Get the number of disks it's to start with, in main(), and call Hanoi() and off you go.

My caveats to you are:

1) The recursive version I have, is in another language, so I'm interpreting this a bit. I …

Adak 419 Nearly a Posting Virtuoso

The key to the game is that if you are at any time, needing to move a stack or substack, you will use the following:

1) if the stack/sub stack has an odd number of disks, you'll move the disk in question to the goal needle

2) otherwise, you'll move the disk to the non-goal needle

This IS a classic recursive program example, but it can be done iteratively, of course. Step through your code with say, two disks, and make sure that's working right. Then, step up to three disks, and go from there.

Find out exactly where it's failing - and what logic is causing it.

Adak 419 Nearly a Posting Virtuoso

We're designing a new program, because the other program was off the mark, rather far, imo. Also, this is what you should develop skill doing. It's one thing to add some function to a working program. It's quite another thing to resurrect the "dead" one's.

A bit of top down design - put off the non-essential details. Get the "backbone" of the programs flow, in place first. Three functions are common in any program - not always needed, but common: input, output, and main. Others for computations, if needed (not needed here).

I'll do the input function. You make the output function. The "blah blah", is just to show that what will go in there is a detail - and I'm putting off the details, for now. (etc., is common however ;) )

Adak 419 Nearly a Posting Virtuoso

The trick is to keep in mind that C always passes parameters to functions by copy - the description "by value" or "by reference", is just an effect of copying either a value (like a variable), or an address (like a &value or array).

And remember that local variables from inside a function, go out of scope when the program returns. They die and go to variable heaven ;)

For your functions, since you can return one value, I'd return the length of the side, like so:

int getSide(void) {
  int length;
  printf("\n Enter the length of the side: ");
  scanf("%d", &length);
  getchar();     //pulls off vestige newline char on kboard buffer
  return length;
}

Then "catch" the return value:

int side1,side2, side3;
side1 = getSide();  
side2 = getSide();
side3 = getSide();

The value "length" from the function MAY still be available after the program returns from getSide() - C doesn't just "erase" variables like that - how long it stays "alive" is up to your compiler and OS. It can be over written, at any moment.

Adak 419 Nearly a Posting Virtuoso

Making an array of 310 structs (records). Reading the input from the data file, putting it into the struct, and into the array.

Right now, I'm too bushed to work on it, but later tonight or tomorrow, we'll take it to the next step.

Adak 419 Nearly a Posting Virtuoso

We're not a "do the program for you", forum. We help people with THEIR programs, if we can.

If you really have no code or pseudo code, at all, check out Google for homework sites, and see if you can find a "do it for you", forum.

Maybe hire a programmer? Won't help in a test, but it's something.

WHITE_BOLT commented: not helpful +0
Adak 419 Nearly a Posting Virtuoso

Here's my suggestion:

1) Let's get out of the damn graveyard, looking for something alive. You'll spend more time, and get far less learning done, trying to make a living program, from the bodies of the dead, than if you just wrote a your own program.

The struct part will be about the same. Shit can the rest.

We will assist.

2) Let's use (at least approximate), some good top-down design methodologies. Beats the shit out of trying to resurrect zombie programs.

3) This is the starting point:

You are developing a database of measured meteorological data for use in weather and climate research. Define a structure type measured_data_t (which I have done) with components site_id_num (a four digit integer), wind_speed, day_of_month, and temperature. Each site measures its data daily, at noon local time. Write a program that inputs a file of measured_data_t records and determines the site with the greatest variation in temperature (defined here as teh biggest difference between extrema) and the site with the highest average wind speed for all the days in the file. You may assume that there will be at most ten sites. Test the program on the following July daily data collected over one week at three sites:

ID Day Wind Speed (knots) Temperature (deg C)
2001 10 11 30
2001 11 5 22
2001 12 18 25
2001 13 16 26
2001 14 14 26
2001 15 2 25
2001 …

Adak 419 Nearly a Posting Virtuoso

Pretty much the same way you find your shoes in the morning:

1) scan the floor, find the left shoe
2) scan some more floor, find the right shoe.

Check if the strings are the same, about the same way you see if your shoes are a matching pair:

1) same color
2) same size
3) same style

How would you check if "this string", was the same as "that string"?

1) same letter, in the same place, in two char array's
2) all the way to the end of the string.

strcmp() will do this, but if you want to learn how to program, why not "roll your own" here, and learn a bit.

strchr() will check a string for a left parentheses, and then you can ask it to check a string for a right parentheses.

For both the above, include the string.h file.

Using fgets() to put each row of text to be scanned, into a char array, should be perfect for your purposes.

fgets(NameOfBuffer, sizeof(Buffer), filePointerORstreamName);
Adak 419 Nearly a Posting Virtuoso

Gotta disagree, Creeps.

He's taking a C class at University, so a C++ compiler won't be used by the prof, to grade his program.

And you can't put a comma or a misplaced return, into a C++ program, and expect it to work either.

OK, it would make it marginally easier with the declarations, but it still crashes and burns - so it needs fixing.

Adak 419 Nearly a Posting Virtuoso

Why put a pair of code tag around your code?
It's very difficult to study code in detail, if it's squished over like html text.

I couldn't fix your program - it's pretty sloppy (like having comma's at the end of a line of code, instead of a semi-colon), and unfortunately, you chose to declare new variables throughout the code. That's OK for some (few) newer compilers, but mine won't put up with it. If you declare your variables at the start of the function, then I can assist you further.

Here's your program, with several syntax corrections:

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

#define Max_sites 10 /* maximum number of sites allowed */

typedef struct
{
int site_id_num[4]; /* id number of the site */
int wind_speed[3]; /* the wind speed in knots */
int day_of_month[2]; /* the day of the month written as dd */
int temperature[2]; /* temp in celcius */
}measured_data_t;

//8888888888888888888888888888{
measured_data_t current_measured,
previous_measured,
//88888888888888888888888888blank_measured = {"", 0,0,0,0}
blank_measured = { 0,0,0,0};
//88888888888888888888888888888}
int main(void)
{
/* DEFINE UNITS AND VARIABLES HERE!!!!!*/
int fscan_measured(FILE *filep, measured_data_t *measuredp);

/* Fills in input data into measured_data_t
* Integer returns as an indication of success or failure
* With 1 => successful input of one site
* and 0 => error encountered */
//888888888888888888888888888888int;

//88888888888measured_data_t *measuredp /* output - measured_data_t structure to fill */
measured_data_t *measuredp; /* output - measured_data_t structure to fill */

int status;

//888888888888888status = fscanf(filep,"%d%d%d%d", measuredp->site_id_num);
FILE *filep;
status = …
Adak 419 Nearly a Posting Virtuoso

To find the center column for the first *, you can use either the number of rows in the "tree", or the number of *s, in the bottom row.

So if the bottom row has 7 *s, then 7/2 equals 3. So you should have 3 spaces before the * on the first row. You can use a for loop (outer one), to code this:

//handles the outer row configuration
for(numstars=1;numstars<=botmRow;numstars+=2) {
  numspaces = (botmRow - numstars)/2;

  //handles the spaces before the stars
  for(i=0;i<numspaces;i++)
    print one space here

  //prints out the star/s
  for(i=0;i<numstars;i++)
    print out star/s here
}

So the top row could be seen as:

spc spc spc * spc spc spc

because the top row will always have just ONE star. So all the other char's will have to be spaces. :)

Now for each row, the number of stars increases by 2, and that means the number of spaces on each side of the stars, will decrease by 1 (since there are two sides, and 2 * 1 = 2.

imo you don't want to use tabs for this assignment.