Adak 419 Nearly a Posting Virtuoso

If you want your calculations to be accurate at all, you need to use doubles or floats.

Integer division is especially (spectacularly) diabolical.

And "millage"? Really?

Adak 419 Nearly a Posting Virtuoso

On line #9, add

stringnew[i]='\0';

so the end of string char is in place. Now recompile, and see what you get.

If you are adding newname ONLY to the right hand side, then it should work as is. If you are adding newname into the middle portion of a string of text, then you will still need to add another strcat(), to append the right side of the original text, onto the stringnew.

If that fails, be specific what it's showing for a final result.

Adak 419 Nearly a Posting Virtuoso

No there isn't. There is one to search for a string within a larger string, however.

The general logic would be:

#include <string.h>

use strstr() to locate the word you want to replace. Save the position (pointer) it returns when it finds it. From the start of the string, to the one returned, is the leftSide of the string. Everything to the right of the returned pointer, is the rightSide of the string.

You want to work with these strings in a char array with extra length, because you'll need to shift some letters left or right, to make everything fit correctly, if the string being replaced doesn't happen to be the same length as the string being inserted.

Use strlen() to measure the length of the string you want replaced, and the string you want to insert. Subtract them from each other. If the string being added is longer, shift the letters on the rightSide of the string, to the right, that many spaces. If it's shorter, shift them to the left that number of spaces.

Now with the spacing correct, overwrite the left most spaces in the rightSide part of the string, with the string you want to add.

If you've done it correctly, the string will now be correct. Be sure when you are shifting letters, to also shift the end of string char - even though you can't see it.

Adak 419 Nearly a Posting Virtuoso

The rand() function will repeat the very same numbers, in every run, unless you seed the random number generator ONE TIME, before you use it.

So

#include <time.h>
#include <stdlib.h>

//then
srand(time(0));
//before any call to rand(),

and you'll be all set.

When you get a chance, you'll be miles ahead if you stick with ONE language. You are using headers from C++, and also from C.

Also, the C++ headers are VERY VERY OLD, and now obsolete. OK, they were obsolete 10 years ago, but who's counting. Turbo C/C++ looks like.

Jump over to a modern compiler and IDE like Pelles C, and you will be impressed. If you want C++ though, go with one of the newer C++ compilers and IDE, like Microsoft Express.

Adak 419 Nearly a Posting Virtuoso

I really like Pelles C for Windows. It's NOT C++, but it has an extensive help section, full IDE editor, debugger, profiler, and it's own forum for learning the in's and out's of using it.

There is a learning curve for using it, because it is a Windows program. I use the 64 bit, but actually create 32 bit programs with it, because they're more compatible with older PC's using earlier versions of Windows.

I previously used Turbo C, and one thing I really like about Pelles C is it supports the older headers: especially conio.h, which I had used in a lot of programs from years earlier with TC.

I just click on a box under project --> options tabs, and I can use conio.h functions, just by adding one underline before the regular function name:

gotoxy(), becomes _gotoxy(), getch(), becomes _getche(), etc.

I don't use these much, but some programs require that kind if functionality, and I don't know all the Win32 API's for it.

It also supports the Microsoft extensions, so when I want to run a program that uses Microsoft functions (non-standard), I just click on the "enable Microsoft extensions" box in the very same project --> options window.

A great feature is the way the range is extended for all the different integer and floating point type! You'll love that! That's not strictly a Pelles C feature, but it's still awesome! ;)

Anyway, it has a ton of other stuff, here's the info page on …

nitin1 commented: super cool explanation!! +3
Adak 419 Nearly a Posting Virtuoso

Use the PDCurses library for all the console control you could ever want.

Adak 419 Nearly a Posting Virtuoso

I've used UTC in a research program for 16 years. It is used worldwide for this (and many other) computing projects. It works just fine.

The time you receive over the internet, is UTC time, THEN your PC changes that with it's own offsets, to your local time zone.

Adak 419 Nearly a Posting Virtuoso

Set your system (like the rest of the world), to use UTC (aka GMT or Zulu time).

Why? Because UTC is not affected by Daylight Savings Time changes. It doesn't change for it.

[quote]
The switch to daylight saving time does not affect UTC. It refers to time on the zero or Greenwich meridian, which is not adjusted to reflect changes either to or from Daylight Saving Time.

However, you need to know what happens during daylight saving time in the United States. In short, the local time is advanced one hour during daylight saving time. As an example, the Eastern Time zone difference from UTC is -4 hours during daylight saving time rather than -5 hours as it is during standard time.

[/quote]

Adak 419 Nearly a Posting Virtuoso

OK, but nothing was swapped. A swap of values doesn't mean simply reordering the variables in the print statement.

Adak 419 Nearly a Posting Virtuoso

You've started coding, before you finished thinking about how it should be done.

The array name should be arr[], not array[], correct?

Think of the logic:

make an array prod[] equal in size to arr[]. Do you know how to use malloc()?

Then

for(each value in arr[] except the current value you are on as you traverse through the array of arr[])

multiply all the other values in arr[]
and put that value into prod[i]

end of for loop

Is that what you need to do?

Adak 419 Nearly a Posting Virtuoso

Syria has a great need for humanitarian help - US and it's Allies can assist there, (and is) in Jordan.

The civil war in Syria will have to be sorted out by the Syrians (plus any other fighters from Islamic countries that will participate). It will be a huge war, because the Rebels underestimated the strength of Assad's regime, after he started getting help from both Iran, and from Hezbollah, too. Not to mention the assistance from Russia.

Some have mentioned that we owe it to Syria to help the Rebels. No, we don't. A good portion of the rebel militias fighting in Syria, have ties to Al Qaeda. Indeed, some are from the same groups that killed our Ambassador in Libya.

Neither Assad, nor the Rebels, have EVER been friends to the US. Indeed, the Rebels "Free" alliance had a burning Washington Congressional Building photoshopped pic, proudly displayed in the background on their web site.
Assad, of course, has attacked our ally Israel, numerous times over the years. You don't have to be political savant to figure out that we're not anybody's buddy in Syria.

Frankly, if chemical weapons are the problem (and they appear to be), removing them from Assad's AND from the Rebels control, sounds like a great idea - even if it takes a lot more time and effort.

Obama's proposal to fire missiles and such, shows he had bad advice from his cabinet, and advisers. You can't do something like that (especially after you …

mike_2000_17 commented: Agreed! +0
Adak 419 Nearly a Posting Virtuoso

Not &test with fscanf, just test.

char arrays don't require an ampersand, like numeric variables do

If you have other problems, specify what they are.

Note that gets(), while it's very convenient, is totally unsafe from buffer overflow, and has been removed from the accepted C standard.

Adak 419 Nearly a Posting Virtuoso

To optimize a program:

1) remember your first priority is always an accurate program. A wrong answer might be infinitely fast, but it's still wrong, and probably useless. Get and keep your program accurate.

2) the largest optimizing you can do, (by far), is with the choice of the algorithm for the program. It's not unusual to get a 2 to 20 x faster run time, simply by using a better algorithm. Choose this with care!

3) run the program, with a profiler, and find the bottlenecks. Concentrate your optimizing work on the code where it's needed most.

4) create a small but relevant test case with typical data. You want a test case that runs for one to two minutes. Include run time from the computer, right into your test case. Now you can easily try different optimiziations, easily, and have real data - not the hand waving or hot air theorizing that we see all too often.

If you post your test case on programming boards, you are very likely to get a large response from the members - because they can d/l it and test it themselves, they get more involved.

Adak 419 Nearly a Posting Virtuoso

Your switch statement only deals with numbers up to nine. As Moschops suggests, you need to deal with each digit of the number.

One easy way to do that, is to change the number, into a string of chars. Then deal with each digit in the array of chars.

Adak 419 Nearly a Posting Virtuoso

Using Pelles C, you should use the compiler in the IDE. Whatever options you want, you can change the compiler flags being passed to the compiler, right in "Project" ---> "project options".

That way you don't have to keep keyboarding in a bunch of flag options. I use the default options a lot. Use "enable Microsoft extensions", for any program that uses the "windows.h" include file. You should read up on the Pelles C introduction which is included in the help section. There's a lot of stuff there. ;)

The type of project I use is Win32 console. It supports big integers (up into the billions), with unsigned long long int. I have the x64 version (because the PC has a 64 bit OS with 64 bit hardware, but I just don't need anything more than several billion. (I got used to using a work around for counting up as high as I want, from DOS days).

For help with Pelles C, absolutely the best thing is to register (free), on the Pelles C forum, at:
http://forum.pellesc.de/index.php

They have a "Beginner section", although you aren't limited as to where you want to read or post. LOTS of good stuff on there, and you WILL need it, from time to time, so sign up!

Your compiler errors are a result of an earlier error in your program. Post the code, and remember to use the compile button in the IDE, not the command line.

somjit{} commented: lots of helpful details :) +3
Adak 419 Nearly a Posting Virtuoso

Your printf() line of code is a great example of programmers being oh-so clever, while ignoring the virtue of clarity in their code.

If you had written that line of code for me, as your employer, I would give you one warning - and on the next occassion, FIRE YOU, immediately.

Programs are not gilded showcases for your mental gymnastics of code. When a program needs to be modified, de-bugged, or worked on by someone else, the value of being clear, rather than unnecessarily complex, will immediately become apparent.

Adak 419 Nearly a Posting Virtuoso

Line 23, remove the & from that line.

rename struct temp tempSt, and make changes so it's clear which is which.

Adak 419 Nearly a Posting Virtuoso

The newline is indeed picked up by fgets(). If you think about it, the newline is THE thing that creates or defines a line of text, isn't it?

This will get rid of it:

//add to your include header list:
#include <string.h>   

//in your function where you are reading the lines of text:
char *ptr;

//read your line of text here
while(fgets(buff.... etc.) {
   ptr=strchr(buff, '\n'); //get the address of the newline at the end of the line (or null)
   if(ptr)         //if it was there - if space isn't available in buff[], it won't be there
      *ptr='\0';   //replace it with the end of string char
}

And you're good to go.

Adak 419 Nearly a Posting Virtuoso

There is no worse description of a probem than "it's just not right"! :(

Give a specific description and an example of the problem.

"Just not right" ---> WTF!

Adak 419 Nearly a Posting Virtuoso

To print in landscape mode, you can either use a printer feature, or a program like you're talking about, here.

If the printer has a landscape feature, then obviously you want to just send it the code to switch it into landscape mode. That feature is not available on all printers, and the code to activate it, if present, would not be the same for every printer. It should be in the owner's manual.

For a program, you'll want to bring the data you want to print into an array, and then rotate the array either 90° left or 270° to the right.

I have a program that does this rotation - but note that it only rotates arrays that can fit into memory. Larger arrays would need to be rotated in a "block by block" kind of algorithm.

Can you fit your data into one single malloc'd or global array? These are arrays created on the large "heap" memory space. An array created inside a C function is by default, created in a small stack of memory, and should not be used for this.

Looks like you're using FAR memory, so this is Turbo C/C++ with 16 bit compilers? Gruesome! As much as I liked turbo C/C++, it's days are LONG gone - free x32 or x64 C or C++ compilers are out there.

Edit: Now I'm confused - do you use FAR memory (addresses) on your compiler? I thought that was only 16 bit compilers that used it.

Adak 419 Nearly a Posting Virtuoso

The more common convention would be 1, 0, or -1. The standard may allow any value > 0 < 0 or 0 (as is seen with strcmp(), a very similar function).

The negative value in one, and the positive value in the other, is a problem however. Could it be that the sizeof(int) is different on these systems, when you print it out?

Adak 419 Nearly a Posting Virtuoso

Interesting. Stanford and MIT (among several others), also have computer classes/lessons on-line.

There are several other "problem/challenge" computer programming sites also:

These are the two problems I've helped with:
Codechef: http://www.codechef.com/BTCD2012/problems/DOORS
SPOJ: http://www.spoj.com/problems/TDKPRIME/

And the funniest of them all:
http://www.ioccc.org/

hilarious! ;) Park your C code sanity, at the door!

Adak 419 Nearly a Posting Virtuoso

You could start here:
http://www.daniweb.com/software-development/computer-science/threads/13488/time-complexity-of-algorithm

Wikipedia has a couple pages on it. Start here, and follow the links to Big O Notation:
http://en.wikipedia.org/wiki/Analysis_of_algorithms

Eratosthenes was an interesting Greek - brilliant and well balanced in several sciences, he became known as "second" when he entered several math/science contests and came in second place. He was the head librarian in the famous Alexandria library, when it had the world's greatest knowledge resource.

He got the (very) last laugh it seems, since his Sieve for finding primes can be optimized easily, and runs in first place (fastest time), for all the ints you can fit into an array, without causing swapping to HD.

Google up "Euler Project" for a series of computer/math challenges.

Adak 419 Nearly a Posting Virtuoso

There are WAY too many algorithms to remember even the most important one's. Because depending on what the program is doing, LOTS of them are very important.

I'm a hobbiest, and never took anything beyond the first semester of C, but I've got a FEW years of hobby experience with it, so:

I try to match the speed (complexity) of the algorithm, with the job. No sense trying to optimize a telephone directory sort by name, when it's your own personal directory, with 100 names or less. On the other hand, if it's the county/district directory, with 5 Million names - yeah, that's worth a very fast algorithm.

Fast algorithms I like:
Insertion sort - for almost sorted arrays, and all small one's (less than 1,000) say. Oddly, it's faster than anything else for sorting small and almost sorted arrays.

Except of course, for the King of Fast:
Counting sort - limited use, but BLAZING UNMATCHED speed, if it can be used. (which is rare)

Quicksort - with Insertion sort on small sub-arrays to optimize it, if it REALLY needs the best speed. Pick first + last value of each sub-array/2 for the pivot. Uses minimal amount of extra memory. You hear bad mouthing about it - well, not if you pick the pivot this way.

Merge sort - for large external data that can't all fit in memory.

Binary Search - great general purpose searcher of sorted data. Don't use it for tiny jobs, but ALL the …

tux4life commented: Nice list ;) +13
Adak 419 Nearly a Posting Virtuoso

Thinking more about your post, I'm not sure whether you wanted a more optimal program, or a simpler - clearer - program. If it's simpler and clearer, or for a small assignment/job, then I would use strstr(), (part of the string.h include file definitions), in a loop:

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

int main(void) {
   int n,len;
   char text[273]={"I am the eagle, I live in high country, in rocky\n"
   "cathedrals that reach to the sky. I am the hawk,\n"
   "and there's blood on my feathers, but time is still turning,\n"
   "they soon will be dry. All those who see me, and all\n"
   "who believe in me, share in the freedom I feel when I fly."};

   char target[273];
   char *pch=text;
   printf("\nOur text is: \n%s\n\nEnter the string you want to search for: ",text);
   fflush(stdout);
   scanf("%[^\n]",target); //take all input up to a newline
   printf("\nOur target to search for is: %s\n\n",target);
   len=strlen(target);

   n=0;
   while(pch>(text-len)) {
      pch=strstr(pch, target);
      //printf("\ntext: %P   pch: %P  Press enter when ready\n\n",text,pch); getchar();
      if(pch) {
         printf("%s\n\n",pch);
         ++n;
      }
      pch+=len;
   }

   printf("\nTarget was found: %d times\n",n);
   return 0;
}

But this program has a problem. Try searching for:
in rocky cathedrals that reach to the sky.

And it can't find it. The problem is the newline - the target doesn't have one, right after "rocky", and the text phrase, does have one.

So you'd have to search for"
in rocky
cathedrals that reach to the sky.

Which would require replacing [^\n] in the scanf(), with maybe[^~], or other …

Adak 419 Nearly a Posting Virtuoso

Code is useless at this point. Not your code, but ANY code. First, before ANYTHING ELSE, get the right algorithm. And you don't have it.

No amount of optimizing later will overcome the problems of a poor choice in the algorithm.

And this is the algorithm you should be studying:
http://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string_search_algorithm

THAT is the most widely used string searching algorithm, and at that link, at the bottom of the page, is a link to a C example showing it.

What's wrong with your algorithm? You are stepping through the string by merely 1 char at a time.

ONE CHAR AT A TIME

Think about it. How could that be improved?

The thing is, you need to work it through with paper and pen several times, by hand. Do YOU check for a string inside a larger string, by checking EACH AND EVERY CHAR?

Of course not!

What do YOU do? Work it through several times, S-L-O-W-L-Y, and notice the pattern that your eye and pen follow doing this. The pattern will reveal itself if you repeat it enough.

And do read up on Boyer-Moore, for all kinds of hints. You don't need to use all their tricks, but you should use some of them.

Save this code, and later, put a timer in it and compare it's time, with Boyer-Moore's program. The difference is astounding if the text being searched is large. The larger the sub-string, the quicker BM's algorithm gets.

Adak 419 Nearly a Posting Virtuoso

We've all been there, Tadas. That's half the motivation to get better with our programming, to be honest. ;)

Welcome to the forum!

Adak 419 Nearly a Posting Virtuoso

One = is for assignment ONLY. Two ='s are needed for comparison: c==0. Since this is already true, the loop never starts.

Use

for(i=0;i<10;i++)
   printf("%d\n",i);

a is zero, so adding it to i will make no difference.

Adak 419 Nearly a Posting Virtuoso

Line 14 is an example of your problem, for all your for loops:

for ( i = 1; i <= NUM_VALUES; i++ )

Which is wrong. correct is:

for ( i = 0; i < NUM_VALUES; i++ )  

You need to MEMORIZE this idiom! This is C, and C has zero based array!

Adak 419 Nearly a Posting Virtuoso

I don't understand the problem of getting info from inside the switch statement. It's the same as getting info from anywhere else in main().

Adak 419 Nearly a Posting Virtuoso

Line #102, remove the &
I would consider changing phno to a string, because it's possible that an integer would overflow with a long phone number - just a suggestion however.

You didn't ask any questions, so I'm not sure what to answer otherwise.

void main() should always be int main() with a return of 0, btw. That tells you (if you want), wether the program ran to completion or had a run-time failure.

Adak 419 Nearly a Posting Virtuoso

OK, keep going! Sounds like you're on a roll. ;) If you have a specific question, be sure to post your latest code - otherwise I'm blind to your changes.

Adak 419 Nearly a Posting Virtuoso

There is no output of the customer info, so what do you need? Number of days, and name of the client, and the type of vehicle would seem required minimum.

Do you need anything else from the custome? Maybe address, payment type, or ???

Adak 419 Nearly a Posting Virtuoso

Do you need to print out one customer's details at a time, as they rent a car, or do you need to print out EVERY customer's details, maybe at the end of the day or week?

I'm trying to see what you need for your output - one customer details output at a time, or several at a time?

Adak 419 Nearly a Posting Virtuoso

You need to specify what these "details of the customer", are. They we'll show you how to make a struct to tie all them together, into one record.

what data types are these details, how many details are there, and what do you want to name their variables?

Adak 419 Nearly a Posting Virtuoso

Well, void main() should be int main(void), with a return 0 at the end of it (in main).

Having all your code in main() is awkward, you should break it up into fucntions. Usually, every option in the switch statement, gets a new function.

And then you need a big do while loop for the menu itself (which should probably be in a separate function), so the menu can show itself for the next customer, without having to be restarted.

Post up your questions and problems - it's good to see your code (essential really), but people can't respond to problems that you haven't brought up, or answer questions you don't ask.

Good start though. I like the use of the switch statements, and your indentation makes it easy to read your code - so that's a very good start.

Adak 419 Nearly a Posting Virtuoso

It's OK to be somewhat stubborn, but when you're wrong, is not the time. Of course, they're built to different standards, they're years apart, and from different lineages, as well.

Don't be that silly student who uses a different compiler than his teacher, because he "has preferences". ?? This is not speed dating!

Get with the program.

Adak 419 Nearly a Posting Virtuoso

Perhaps you are using the angle of 45 you have defined, instead of calculating the real angle on the bounce off the bricks, or the wall.

If you Google for that equation, you'll find it easily. I don't have it on this system, but it's simple geometry.

Adak 419 Nearly a Posting Virtuoso

Make your printf() format, occupy 80/number of columns you want to have including spaces between columns.

If I want 4 columns, I have my printf() format use 20 spaces, etc.

#include <stdio.h>

int main(void) {
   int n;

   for(n=0;n<200;n++) {
      printf(" %18d ",n);  //4 columns, each one 18+2 wide.
   }
   printf("\n");
   return 0;
}
Adak 419 Nearly a Posting Virtuoso

In C, ALL parameters are passed by copying - NOTHING ELSE. When you copy an address (pointer), you have a way of affecting the original variables that are pointed to by the address - so it's a pass by reference, in it's effect.

You pass a 2D array to a function, by just using the name of the array, in the call to the function:

myfunction(arrayName);

In your function parameter list a 2D int array like this:

void myFunction(int arrayName[][NumberOfColumns]) {
   //other code in here


}

Note that the number of rows (in the first [], is not needed. All other dimensions size, need to be included, however.
NO *'s are needed, at all, which seems to be the confusing factor.

Arrays in C are ALWAYS passed by the address (which is the name of the array most commonly). The receiving function has to have the greater share of explicit info about the array, if it is to be treated as an array - instead of just as a "something" at a certain address. (which is also possible, but not recommended - especially for beginners). In this latter type, you are working explicitly with pointers (addresses) and offsets, which makes it not as easy to understand.

Adak 419 Nearly a Posting Virtuoso

Why not add a print statement with two getchar()'s afterward (to pause the screen) the first time through the loop, and print out exam[0] and correct[0] and see what's going on?

It looks right, but sometimes the errors are just too simple to catch with a look through.

Are you compiling or running this program in Debug mode? If so, try a release mode. Sometimes debug mode gets twisted 'round.

Adak 419 Nearly a Posting Virtuoso

Personally, I'd use fgets() to get the whole line of text from the process file:
fgets(charBufferName, sizeof(charBufferName), filePointerName);

which easily gets 1 line of data, and in a while loop, gets every line of data:

int i=0;
while((fgets(buffer, sizeof(buffer), fpName)) != NULL) {
   //then use sscanf() to get the data into your arrays:
   sscanf(buffer, "%s %s %s ", array1[i],array2[i],array3[i]);
   ++i;
}

strtok() is fine, but you always have to watch out for what you can't see - that it changes the string it's tokenizing.

Adak 419 Nearly a Posting Virtuoso

I see your code makes comparisons with doubles - which is quite hazardous. Floating point numbers can't represent all values - they have to (very closely) approximate some of them.

The "cleanest" way to work with numbers that must be compared, is to use a multiplier, and then cast them to integers. So 100.68 would become 10068, for example. Do that RIGHT AWAY, with every float value. Then, for your output, cast it back to a double, and divide it by the same power of ten that you multiplied it by.

Another way, is to make your comparisons within a small range, instead of a fixed value. if double > 4.89 && double < 4.91 kind of logic.

If you google for "problem comparing floats", you'll find a lot more info on it.

Adak 419 Nearly a Posting Virtuoso

So far, you haven't shown any of your own work - and copy and pasting the requirements of the project, certainly doesn't count as work on your project.

So we have no idea what you're stuck on.

Get started on your assignment, and when you get stuck on something, post up about the problem you're having. Be specific! "This doesn't work" on a post, just doesn't give us much to go on.

Use how you would do this work by hand (paper and pencil), and use the same patterns of work and logic, to design your pseudo code. Then use your pseudo code, to design your program. Work through an example or two or three, of a students grading by hand, and you'll see the pattern emerge. Look for it.

And post back when you get stumped on a problem that you can show some work on, and has specifics. General problems take up too much time to try and sort through.

Adak 419 Nearly a Posting Virtuoso

It's quite easy actually. ;)

The key is, when you exceed the maximum of a data type SOMETHING is going to go haywire. When you exceed a positive integer, it might go negative (or do something else).

A simple while loop (or for loop) will get you "close". Just keeping multiplying a test number of that data type, by 2. When you are "close", you might want to get even closer by using a smaller number, say 1.4, etc.

But you have to find out what "haywire" is for your compiler, and recognize it, in your code. When I did this, I found I could go quite a ways past that limit in the header, before it went "bonkers", with the number.

Don't be put off by the huge size of the floating point range - you multiple by 2 and you'll be as far as you want to go with x 2, pretty quickly.

Mine went x2, for N times, then another loop took the number x 1.6, for N2 times, then a third loop took the number x 1.4, and finally addition was used to zero in the maximum value (which was well beyond the value in limits.h).

I don't want to spoil it by posting my code for it - it's a great exercise to build up your problem solving skills.

ak24 commented: Thanks, this helped me a lot. +1
Adak 419 Nearly a Posting Virtuoso

Try Pelles C (a free Windows only C only compiler), and you won't look back to Turbo C. There is a learning curve, but it's not bad at all. MUCH more capable.

Adak 419 Nearly a Posting Virtuoso

The accuracy I doubt, but it fixes the compiler errors:

/* doesn't work, just removing some compiler errors */

#include <stdio.h>

//function prototypes
void read_code(char *julian_date);
void extract_julian(int *day1, int *year1,char *julian_date);

int main(){

char julian_date[8]; /* julian date consists of 7 characters - leave room for the '\0'*/
int day1=0;
int year1=0;

read_code(julian_date);
extract_julian(&day1,&year1,julian_date);

printf("this is day %d\n",day1);
printf("this is year %d\n",year1);
return 0;
}

void read_code(char *julian_date)/*this function is for input*/
{
printf("input the julian date.\n");
scanf("%s",julian_date);
}

void extract_julian(int *day1,int *year1,char *julian_date)/*this function extracts the numbers from the julian date*/
{
sscanf(julian_date,"%d",year1); /* makes the first 2 numbers equal to year*/
sscanf(&julian_date[4],"%d",day1); /*makes last 3 equal to date*/
}

(click on the [CODE] icon one time, and paste in the code)

Adak 419 Nearly a Posting Virtuoso

Welcome to the forum, Roflspanker! ;)

I believe I see the problem, but let me set it up in my compiler.

Your code tags were perfect - except one [ char got skipped, somehow.

Adak 419 Nearly a Posting Virtuoso

Oh yes!

Nothing personal, but I really dislike your code:

1) It's int main(void) or int main(int argc, char *argv[]), never just main or void main.

And always with a return (usually zero) to signify success to the OS and you.

2) Your indentations are an affront to real estate on the monitor. 2 to 5 spaces is plenty per level of indentation. Your style will run you right off the row, with most real programs.

3) Your sort is an OMG! Bug city hotel. It's so long, and so error prone to work with, it's just incredible.

C should be CONCISE, (short, and to the point), not a Rube Goldberg deluxe creation. Simple and clear are secondary goals to accuracy, but important one's nevertheless.

A good sorter should be 5 to 30 lines, depending on what you choose, and what function is doing the swapping.

4) Your braces (opening and closing), should vertically line up on the same column. Yours are FAR offset.

5) Why is an add function, an output function in your comments? BTW, this is how your sorting should be - concise!
This function, I definitely LIKE! ;)

Your code is wonderfully playful, great creativity, but never show it to someone as something like working code you wrote. If you ever need to extend or modify it, after you've been away from it for awhile, you will see what a nightmare on Elm St. it …

Adak 419 Nearly a Posting Virtuoso

A good simple way to do this is to always use two nested for loops:

An outer for loop to control the row variable(s)
   and an inner for loop to control the printing on that one line currently being printed.

Think of it like you are always going to print a box, and the box is made up on each row, with spaces and *'s. There is a relationship between the row you're currently printing, and the number of starts that need to be printed. Also, the number of stars, and the number of spaces, equal the width of the box. That is true for every row, regardless.

You may now safely and full confidence, chuck your code in the dust bin, and promise me you will not try to use such as that again. ;) It's all about using loops. Otherwise, it's headache city!