Adak 419 Nearly a Posting Virtuoso

Line 53, remove the semi-colon from the end of that line. Remove lines 61 and 62. Line 94, put a space before the % in the scanf-- scanf(" %c", &entered_char);

Line 96, you need to surround both logical arguments in your if statement, with parentheseis:

if((argument1) || (argument2))

Line 102, delete the word char in that line. The variable is already declared in your program, you can't /shouldn't re-declare it.

You should be re-compiling your program frequently, to catch any syntax errors before they cause zillions of other errors during compilation.

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

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

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

Instead of explicitly printing every every * with another line of code, you want to use loops and if statements, etc.

Think more like this, in pseudo code:

get the height and the width of the box, from the user
for each row
   move the cursor along the width of the box
   for each column    
      if the column number is the first, or the last one, 
         print a *

      if the row number is the top or the bottom
         print every column with a *
    next column
    print newline
next row    
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

Showing once again why volunteering a program, without the original poster doing any work whatsoever, is a bad idea.

Whether it's homework, or a problem solving website like SPOJ or Euler Project, having us code up a gratis program for them, is just wrong. They did none of the work.

And can you code that in Lisp, Fortran, ADA, Go, Rust, Scheme, Python, Perl, and Brainfuck, for me?

iamthwee commented: nods +14
Adak 419 Nearly a Posting Virtuoso

Do NOT use feof() - it simply doesn't work the way a human thinks it should, and it will goof you up every time.

There are three ways:

1)

while((fgets(myCharArray, sizeof(myCharArray), filePointer)) != NULL) {
   //your code to work with myCharArray[], as you need to
   //fgets always puts a newline at the end of the array for you, space permitting
   //and NEVER overflows your char array. sscanf() is well suited to be used now.
}

2)

while((fscanf(filePointer, "%[^\n]", myCharArray)) > 0) {
   //similar to fgets() above. Reads and stores until the newline
   //as long as as it's able to read and store at least one object (not OOP though)
}

3)

int ok;  //NOT char, int!

while((ok=getchar()) != EOF) {
   //now you're forced to work at the char by char 
   //level, which is usually rather tedious
}

Overall, I'd use fgets() probably. It allows you to scan and find and parse our the char array as many times as you need to, very easily. Be sure to give it a generous size so you'll always have the entire line of text, + the newline + the end of string char: '\0'. To get rid of the newline at the end of the char array:

char *ptr = myCharArray;
ptr=strchr(myCharArray, '\n');
if(ptr)
   *ptr='\0';
Adak 419 Nearly a Posting Virtuoso

You'll have to recurse one time more than you want to, to find the next char, THEN if it's 'I' don't remove the 'b' you were checking out on the earlier depth. Otherwise, remove it.

Likewise, if you recurse one depth and find the end of the string, then don't remove the space or 'b' you're currently on.

Think of it just like a while() loop, but the recursive part of it, handles the "while" (the looping). The base case should be quite similar to the stop for a while loop.

VERY smart to use 'b' instead of an empty space (which is tough to work with in a visual sense).

Give it a try and see what you can come up with.

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

Your array to hold the file's contents needs to be 2D (rows and columns): array[rows][cols].

Each time you want to save a row, copy it to array[rows] - that serves as the array pointer for that row. (In C, 2D arrays are arrays (rows) inside the larger array.)

The general technique is:

char *ptr;
char buff[256];
char array[20][256];  //20 rows, each 256 chars long
int row=0;
//where fp is your FILE pointer and has open the file already
do {
   ptr=fgets(buff, 256, fp);
   if(ptr) {                    //you have good data, not EOF
      strcpy(myCharArray[row],buff); //move the data - it's good
      row++;                    //set up for the next row
   }
}while(ptr);

This avoids putting a duplicate last line of data, (when EOF is reached), into the array, or just having a blank row.

Why is not a great question - many functions in C work with the format or parameters, inside the ():
printf(), scanf(), toupper, tolower() sqrt(), strcpy(), strcmp(), etc. Pointers are typically returned (scanf() for instance), or a number (printf(), strcmp(), etc.).

On line 18 of your code, remove the & from the printf(). That's for scanf().

Adak 419 Nearly a Posting Virtuoso

Whatever you buy, buy something that you will want to use for a long time - robot type projects are not real cheap, and you will want to use it to DO stuff, not just be programmed one time, and sit in a box in the closet.

Look at what you want the robot to do - even if it's to teach you how to program a robot - and get the kit for the robot that best matches your wants and needs. Consider all the aspects of the kit before you get it - every robot I've seen has been designed to be good at some things, but terrible at doing other things. That's not a bad thing, but it means you need to do your research before you buy anything.

Did you register at a robot forum, yet?

harshi414 commented: thanx ! yes i have registered in a few froums but nothing useful ! +0
Adak 419 Nearly a Posting Virtuoso

Your robot will have to have a micro controller, if it is to be controlled by electronics. Since you "don't know about micro controllers", you will have to learn how to program them, because the controller (as the name implies) controls the robot, at a very low level.

We can't teach you, since it's not C - it's hardware, plus a hardware interface to allow the robot to send and receive messages.

I recommend you Google "robots forums", and find a forum that specializes in robotics. Robots are different, depending on their hardware and controllers.

How you program the robot depends on the controller, and the maker of the robot will include instructions on how to do that, for that particular make and model of robot. Some can use C as a user language, others use a variety of different langauges for the user to program their robot. They're not all the same in the choice of languages the user can work with. The last one I worked with had only languages of a special version of BASIC, or Pascal - no C.

Good luck!

ddanbe commented: Good answer! +14
Adak 419 Nearly a Posting Virtuoso

Why not read through the subjects of other projects, and see if that doesn't spark a bit of interest in you. Imo, it has to be something you're interested in.

Also, read through the science news (Google it), and again, see what catches your eye.

Driverless cars? A few are licensed and on our roads, in the US.

Navigation ("GPS") in space using Pulsars is being studied by Max Planke Institute in Germany. Seems we currently can't position our satellites once they get away from Earth, very well.

Argon-Argon Dating is in the news on the BBC website. Best date yet for the extinction of the dinosaurs, and the first placental mammal (non-egg laying).

Plethera of distributed computing projects AND illegal botnets (Symantic and Microsoft just took down a HUGE botnet). The good and the bad they do.

Ex-President Bush just had his email hacked into - interested in securty?

You'll find lots of stuff if you just search on-line. I don't think anyone can direct you to a subject however - it has to be something you're interested in, curious about, etc.

Good luck! ;)

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

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

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

You have a stop variable. Every number that is single, is given a "stop" equal to, the first number read, meaning no other numbers will be printed beyond the first one. Otherwise, stop is given the value of the number after the hyphen (the second number).

So I picture this as a read, followed by a for or while loop: e.g.

int number, stop;
read the number, assign value to stop.
for(i=number;i<=stop;i++)
      print i

How verbose was your code? (How many lines?) I don't believe this is highly optimized, but it seems straight forward, clear and acceptably concise.

Adak 419 Nearly a Posting Virtuoso

In C, a semi-colon marks the end of an expression. On these and other expressions, your semi-colon has cut them off - and you need to remove them.

for ( i=0 ; i<=8 ; i++ )**;**
{
for (j=i+1;j<=9;j++)**;**
{
int temp;
if(array[i]>array[j])**;**
{
Adak 419 Nearly a Posting Virtuoso

I'm no math whiz, but don't you have to find the range of possible answers for a,b,c,d, separately, in every equation, and then look at the range where all 4 variable's ranges, overlap?

Emphasis on the highest and lowest values for each variable, of course. Everything in between should be golden. (good)

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

Just a little program to show the extreme usefulness of Binary Searching (aka "binsearch").

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

#define SIZE 250000

typedef struct {
   char name[30];
   char state[40];
}user;

user users[SIZE][40];    //using memory from the heap, not the local function stack

int binarySearch(char *target, char *states[56]);

int main(void) {
   clock_t timer;
   int i,count,ok;
   char target[40];
   char *states[56]={"Alabama","Alaska","American Samoa","Arizona","Arkansas","California",
   "Colorado","Connecticut","Delaware","District of Columbia", "Florida","Georgia","Guam",
   "Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine",
   "Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska",
   "Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota",
   "Northern Marianas Islands","Ohio","Oklahoma","Oregon","Pennsylvania","Puerto Rico",
   "Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virgin Islands",
   "Virginia","Washington","West Virginia","Wisconsin","Wyoming"};

   FILE *fpIn;
   fpIn=fopen("NamesStates.txt","r"); //250,000 names with states
   if(!fpIn) {
      printf("Error opening file!\n");
      return 1;
   }
   timer=clock();
   for(i=0;i<SIZE;i++) {
      fscanf(fpIn, "%s %[^\n]",users[i]->name,users[i]->state); 
   }

   fclose(fpIn);
   //match all the states in the from the users array, 
   //with the states in the states array,using the binary search.
   for(i=0,count=0;i<SIZE;i++) {
      strcpy(target,users[i]->state);
      ok=binarySearch(target, states);
      if(ok>-1)
         count++;
      else if(ok<0) {
         printf("target: %s users[i].state: %s \n",target, users[i]->state);
         getchar();
      }
   }

   timer=clock()-timer;
   printf("Matches found: %d   Elapsed time: %.3f seconds\n",count,(double)timer/CLOCKS_PER_SEC);

   printf("\n");
   return 0;
}

int binarySearch(char *target, char *states[56]) {
   int lo, hi, mid;
   lo=0;
   hi = 56-1;

   while(lo <= hi) {
      mid=lo + (hi-lo)/2;
      if((strcmp(states[mid], target)) <0) {
         lo=mid+1;
      }
      else if((strcmp(states[mid], target)) >0) {
         hi=mid-1;
      }
      else
         return mid;
   }
   return -1;
}

The above is not an optimized program - run of the mill. But it finds a quarter of million matches of 56 states and territories, in less than 4/10ths of a second, on my PC. Pretty impressive, this algorithm! ;)

This is the data file, which I simply copied …

Adak 419 Nearly a Posting Virtuoso

Sure, but that won't help you. How would YOU solve this - forget the computer for now. Solve it by pen and paper a few times, very slowly.

How did you do that?

Write down the steps you took to solve it, and use small steps. BECOME the tip of the pen, as you are solving it.

Do that a few times, and eventually you will begin to notice definite patterns emerging. Those patterns, will form the backbone of the logic for your program.

This is too good and simple to be giving you ANY hints -- it is VERBOTEN! ;)

Adak 419 Nearly a Posting Virtuoso

Yes, you can.

I have barely worked with this, years ago, but IIRC it was done like this:

1) print the letters out, as per regular

2) Technique #1:
a) use ascii char like 176,177 and 178 (░, ▒, ▓)to "dim" the letters, when you print over them. Then immediately reprint that letter, using bright white (15) color, instead of the dull white normal color (7). Most of the basic colors for the console, have a bright version of it, as well: dull red - bright red, dull blue - bright blue, etc.

It's great to fine tune these techniques by using the milli second timers.

Technique #2:
a) use a variety of extended ascii char's like 220 through 223 to "blank out" a portion (top, bottom, left or right) of the letter (but very fast!). If you do it fast enough, the "blank out" will not hardly be noticed - the letter just seems to pulsate or twinkle.

Technique #3:
a) if you want to see "wings" on the letters, you need to overstrike the letter space next to it with one of the extended ascii (charts available for free download from many sites), char's that has a horizontal extension on it. Print the extension (and you can use more than just hyphens!), where the asterisks * are now

Space the letters one more space apart, and you can give "wings" to every letter, on both sides, and make them "flap". (a little like you're doing …

nullptr commented: Im glad that someone understands what twinkling is :) +4
Adak 419 Nearly a Posting Virtuoso

It's an old school type solution, but I used three int arrays. One for each of the two numbers' digits to go into, and one to hold the "carry" value.

Imagine they are stacked up on top of each other. One digit ONLY per element of each array. Any value > 9, puts the "carry value, into the carry array with the proper (next) index.

Work from the one's column (far right hand side), or you can make it a bit easier and reverse the number, and work from the left hand side (so the indices get bigger in the array's as you loop from first to last digit columns.

Start with a small 3 digit number and see which way you prefer and get the logic worked out, before you jump to bigger numbers.

The process is EXACTLY the same as if you were multiplying numbers together by hand, in grade school.

Laying it out first by hand, (pen and paper) a few times, is a worthwhile experience, since we're so used to using calculators all the time.

Adak 419 Nearly a Posting Virtuoso

Try this. (It works, but you'll need to adapt it a bit).

I changed d to divv, and c to cur. You need to include <math.h> for sqrt() (big time saver).

Be sure to initialize biggest to zero, before the loops start.

//two is handled separately, before this

         for (divv = 3; divv < sqroot; divv+=2) {
            if (cur % divv == 0) { // I have treid c % d too.
               isprime = 0;
               //printf("cur: %d  div: %d \n",cur, divv); getchar();
               break;
            }

         }
         if (isprime == 1) {      //is cur a factor of NUM?
            if(NUM % cur == 0 && cur > biggest) {
               biggest = cur;
               //printf("cur: %lu  div: %lu \n",cur, divv); //shows biggest cur's
            }
         }

      printf("biggest: %lu"\n,biggest);
      return 0;
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 21, add a space before the %c: scanf(" %c",&wordlength). That is needed to "eat" the newline that was left over in the input buffer, from when you hit enter.

Adak 419 Nearly a Posting Virtuoso

You can't use [i] as your index in vowstr[]. i is tied to the entire string that was entered.

BTW, you could have done all this in a single for loop. ;)

Add int m=0, and then use vowstr[m++] instead of vowstr[i], in the if statement

Adak 419 Nearly a Posting Virtuoso

Have you created the products.txt file yet, with the necessary spec's as you describe here?

  1. The product IDs and product prices are stored in a table format in a file named
    products.txt. Create a text file in the same folder as your .c file and type in two columns
    (ID and price) separated by a tab. product ID and price are integers

You can't read a file's data correctly, until you have the file. As I understand it, you will manually type this data into the file, and keep it. I would make a backup copy, just in case - you don't want to have to enter it again if it gets scrambled by your program.

You'll need a FILE *pointer, (of course, *) as use an fopen() to open the file in read mode. Then fscanf() should be all you need, since the data is in a strict format, which will not change.

Give that a try.

Adak 419 Nearly a Posting Virtuoso

First, Welcome to the forum, lp94!

You need to start your program, and then ask for help, on specific problems. We weren't in your class, and this is YOUR assignment.

Think of it as though you had no computer. How would you start this with just paper and pen? Give it a good try and post up your result. Without this requirement, we'd be doing every students homework 24/7. I know you understand.

Adak 419 Nearly a Posting Virtuoso

D'question, I do not d'C. ;)

Adak 419 Nearly a Posting Virtuoso

We would hope that you will tell us what is the problem with the program - then we can focus on a specific spot within your program, to look for errors.

Saves a lot of time, that way, and gives you a chance to develop some better problem solving skills of your own - debugging your program is a skill set that you need to practice to be any good at it.

ALWAYS use code tags around your C code, so it retains it's C indentations! Those are SO important to show the logic in the code, instead of just html (forum) text formatting - which makes code look like something the cat threw up yesterday. :(

Just highlight your code, and click on "Code" in the header of the edit window - done!

I really like the overall design of this program - it's wonderfully compact. Just hard to read through as C code, when it's formatted this way.

Can you repost it and use the code tags, and tell us what the problem is that we should focus on?

Thanks, and welcome to the forum! ;)

zeroliken commented: nicely said +9
Adak 419 Nearly a Posting Virtuoso

Hey you can use turbo c in windows 7 by changing its compatibility..

I changed the following settings to make the window larger :

FONT >
Size = 28
Font = Consolas
LAYOUT >
Screen Buffer Size :
Width = 80
Height = 75

Window Size :
Width = 80
Height = 75

I'm a LONG time lover of Turbo C, but c'mon - it's days are over. Time to move on.

Coaching newbies on how to run their car or bike, on flat tires is not good! ;)

Pelles C is so easy and good for Windows C (32 or 64 bit), and no C++ junk in there.

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

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

Wrong format. Use:

filePointer = fopen("filename", "w");

Your file mode letter can be "r", "w", "a" "rt", "wt","rb" or "wb". The one's with a b are for binary mode, t is for text (and your system may have a default set by a variable option for your system). You can also use + between the letters, etc.

You should check your filePointer to be sure it's not NULL after the open line of code. It's common to have a filename be just a letter off, etc. Filenames are case sensitive, btw.

Adak 419 Nearly a Posting Virtuoso

Control+Z (aka ^Z), is the end of file indicator, for DOS and Windows (all versions). It is an integer, and can't be detected as a char. So there's your while (or for) loop:

while(first integer != EOF) {
    //your code here
}

Whenever possible, use integers as your data type, not floats. Here, you have floating point variables for the number of cars!
I doubt very much if 0.22 of a car, will every use your parking lot! ;)

Be sure to change your scanf() and printf() format indicators, as well.
And look at that! You need an integer to test for EOF, and now you know you also need an integer for other data, as well. What a coincidence! ;)

Adak 419 Nearly a Posting Virtuoso

That's not how the forum works. We aren't a "do your homework for you" forum. We are a free "help you out when you get stuck on your homework, and show real effort", forum.

It's all up to you to get the project started. It's a pity you have no idea of how to do your project. Perhaps you should ask someone in your class, or even the instructor, how to get started. You've tried searching for information on this, at Google?

Adak 419 Nearly a Posting Virtuoso

Thanx Adak. That helped. What really are these Environmental Variables? and purpose do these paths serve>

Environmental variables tell the OS where your OS is found, and other system info, that it needs, while it's booting up (and uses from then on). The PATH for instance, tells the part of the OS that is booting up, (which it finds from the master boot record), where to find the rest of the files - programs for the dll's to run, and all the so-called "external" commands of Windows. (External commands are commands that either use a lot of memory or are used less frequently. The OS doesn't keep these in memory, but loads them only when you need them.)

If the Turbo C directory you're running from is not in the path, any system() lines of code will crash the program it's in, or be ignored. All depending on the phase of the moon, and the lottery numbers that week. (in other words, it's undefined).


In WindowsXP, (and probably other versions as well), it's a bit confusing because it has two command shells: command and cmd. Command is the normal Windows command shell, while cmd is the console command shell, which can work with DOS sized programs of 16 bit. Each one of these has it's own separate configuration file ("config.sys" for cmd), and autoexec.bat (for cmd), file. In addition, the registry has PATH and other configuration info, stored in it. Windows 7 will not run the …

Adak 419 Nearly a Posting Virtuoso

DOS had a path environmental variable, in a file named "config.sys". Windows has something similar, sometimes it uses config.sys, and sometimes it uses another file, depending on the version. The registry also has data on this.

Best answer is to look up PATH in your Windows help, which will have the right info for your version of Windows. In some versions, you can change your PATH (careful now!), right in Control Panel, look for the System >> environmental variables tab, iirc. In Windows 7 it's:

Control Panel >> System >> Advanced System Settings >> Advanced Tab >> Environmental Variables button.

Adak 419 Nearly a Posting Virtuoso

Thanx Adak. You are right about my sofware engineering ambition. I am running DOS under windows and I am totally cognisant of the fact that DOS is cadevorous rotting operating system, but don't you think that learning DOS before going for windows could give me a better understanding of how things work at the elmentary level, and how things really began manfesting.

Also let me know if you can provide me with some useful resources which you think might be of help, especially if you have things regarding Intel Processors and their architecture and instruction set.

I would skip DOS, then. Google up info on the 8088 or 8086 cpu (first PC cpu), and then work your way up through the 80186, 80286 and especially the 80386. The AMD (not Intel) design for keeping compatibility with 8088 software, while moving to a flat memory model, etc., was a HUGE breakthrough. Intel couldn't match it, and paid big bucks to use the AMD design (which is still the basis for the cpu, although it's been enhanced many times over by both Intel and AMD).

For hands on learning though, you can't beat the simple(r) micro boards like Arduino, and etc. Those little kits are a blast and a half, and (if you don't burn them up), then can be used for several different projects. There, the simplicity of the board makes so many things jell in how digital micro electronics work.

You can't run TSR's on top of Windows …

Adak 419 Nearly a Posting Virtuoso

I used to have a book with some examples of this - haven't seen the book in years, but I'll look around and see if I can find it.

The problem with TSR's was, they would work on PC's with a certain design, and peripherals, and OS, but anything else was a maybe, and the further you got away from the author's design of PC, the less of a chance there was of his TSR programs (or any assembly program), working.

TSR's worked if they were made for a particular PC and OS, etc., but they were never officially supported by Microsoft, unless they were made by MS.

From your other forum's posts, I believe you'd really like software engineering, and a small microprocessor board based project, would be right up your alley. Have you looked into any of the Arduino board or other micro board forums/projects?

The more you look into TSR's, the more you'll find they're sort of the smelly rotting corpse, end of the PC engineering world.

But I will look for the book. ;)

What version of DOS are you running? You're not running this inside a Virtual Box/Virtual Machine type environment, right?

Adak 419 Nearly a Posting Virtuoso

Try it, it won't bite you. ;)

To learn to be a problem solver, you have to explore the world of code - roses and thorns, as well.

sergent commented: agree +6
Anuradha Mandal commented: I also agree. +0
Adak 419 Nearly a Posting Virtuoso

OK, you're serious.

The for loop is the more complete loop. In fact the Go language from Google, doesn't have any loop other than the for loop. Anything you can do with a while loop, you can do with a for loop.

The while loop doesn't include an inital assignment to the format, so it's standard idiom to see one or more assignments before the while loop begins:

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

The typical while loop includes just a test between it's parenthesis, but here's one with an assignment first:

while((ch=getchar()) != '\n') {
  countchar++;
}

The for loop syntax in C, requires more than just a single value in the while test:

i = 0;
while(1) {
  if(i++ == 9) break; //a break is required or it's an endless loop
}
for(1) { <<== illegal syntax

for(;;) { //legal, note the two semi-colons
  if(i++== 9) break;
}

So at a deep logic level, there is no difference between them. Anything you can do in a for loop, you can also do in a while loop, and vice versa.

In common usage, when you know the number of times the loop will need to iterate around, then a for loop is more intuitive. When you don't know how many times a loop will need to iterate, then a while loop is slightly clearer, and is usually used.

Adak 419 Nearly a Posting Virtuoso

If you just want a programming problem in C, this forum is absolutely FULL of them.

Counting the words in a paragraph of text, finding a word in a sample of text, encrypting text with ROT-13, (or something stronger), efficiently finding all the prime numbers from 1 to 1,000,000, compare a binary search with a linear search for two different sizes of int arrays: 1000 numbers for 1 array, and 100,000 numbers for the other. What's the total time for finding 100 numbers? Draw a tire on the console, complete with sidewall, using ascii-like char's only. Make a Hangman game, or Tic-Tac-Toe. Draw a circuit roughly with ascii-like char's, and let the user input the resistance he needs, in total. Using just three resistors, calculate and show what the band colors and values should be for each resistor.

Go to Project Euler and tackle one of their problems.

Ancient Dragon commented: Project Euler excellent suggestion +17
Adak 419 Nearly a Posting Virtuoso

When you are sorting, you always need to know how many items you need to sort. It's very common to have an array of 100 elements, but only have 68 data items in that array, that are valid. The rest are just holding junk values or zeroes.

Another tricky thing is that your sizeof() function for arrays, only works for global arrays, and arrays that are declared in the current function.

So any array that you bring into a function as a parameter, you can't use sizeof() on. If you try, you'll only get the sizeof() a pointer to that data type - because arrays degrade to a pointer when passed to a function. So you need to always pass the size of the valid data around (or the size of the entire array if it's completely full of good data), when you pass an array to a function.

Trippy stuff!

Ancient Dragon commented: good advice :) +17
Adak 419 Nearly a Posting Virtuoso

Look at a matrix 2 x 2, with 0-3 for values:

0   1
2   3

When this matrix is turned 90° clockwise, where will each element wind up?

0 - goes to top row right column
1 - goes to bottom row right col
2 - becomes top row left col
3 - what does 3 become?

What relationships do you see in the above? The position of the value before the turn, let's call pos0. The position after the turn, let's call pos1.

pos1 = pos0 if column of the value, becomes the row. That is, the 0 column, becomes the 0 row, the 1 column (1 from the leftmost column), becomes what row?

Note that I'm always counting from the leftmost column, from left to right. That works fine when the rotation to be made is clockwise. If it's counterclockwise, then you start counting at the rightmost column, so that's the column that becomes column 0. The top row still is row 0, next row down is row 1, etc.

Work with a simple 2 X 2 array until you can see what I'm prattling on about here. Then try it with a 3 X 3 array, and work through it, this same way.

If you don't see it at first, keep working with it. The lightbulb WILL go off * POOF! *

;)