Adak 419 Nearly a Posting Virtuoso

IIRC, you needed to create a new project - to always have a "default project", so the IDE would have one to open.

In your borland directory (either TC or TC/BIN), you should have a readme file that has a lot of info on stuff like this.

Adak 419 Nearly a Posting Virtuoso

Your program is written in C++, so you're in the wrong forum.

An if statement in C looks like:

if(test statement) {
  //test statement was true or non-zero
  printf("\nThat statement was true or non-zero.\n");
} 
else {
  //test statement was false or zero
  printf("\nThat statement resolved to false or zero.\n");
}

The else part of the if statement is not always necessary, of course.

Hope that helps.

Adak 419 Nearly a Posting Virtuoso

P.S. Before you start the first while loop, set i equal to 0.

Adak 419 Nearly a Posting Virtuoso

575,00 0,0 0,0 0,0 0,0 0,0 0,0
580,00 1,0 0,0 0,0 0,0 0,0 0,0
587,00 2,0 0,0 0,0 0,0 0,0 0,0
633,00 3,0 1,0 0,0 0,0 0,0 0,0
675,00 4,0 2,0 1,0 0,0 0,0 0,0
726,00 5,0 3,0 2,0 1,0 0,0 0,0
801,00 6,0 5,0 3,0 2,0 1,0 0,0
907,00 7,0 6,0 4,0 3,0 2,0 1,0
988,00 8,0 7,0 6,0 4,0 3,0 2,0
1.048,00 9,0 8,0 7,0 6,0 4,0 3,0

OK, let's say the above is your array, called table. Income is the far left, and adjustment for number of dependents, is in the other columns.

so your logic could be, first, get the right row:

get toFind //income to find the rate for
while(toFind <= table[i++][0]); //note the semi-colon here

//you have gone one row too far, so decrement i
--i;
//and now you have the right income row.

Now, wasn't that easy? ;)

You can repeat the type of logic above, for dependents to get the adjustment right, but you can see that dependents = dependents +1 in the table, above, so.

dependents = 3;

get the right row, as shown above, then

income = table, and dependents adjustment = table[dependents+1]

It's easier, imo, if you load the data for the table, into a 2 dimension array[][], instead of working with the data in a file.

Adak 419 Nearly a Posting Virtuoso

Some compilers (like the older Turbo C) will "give" you 5 to 9 elements of a failed array, even though the request for the array, failed. At least, it appears that way. The failed array will work for up to 9 elements, maximum. Try size 20 though, and it will fail every time.

That's what you had.

Stick with the standard for C, and you'll be fine.

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! *

;)

Adak 419 Nearly a Posting Virtuoso

Forget your code. Take a pencil and paper, and draw your array of 4 x 4 (or 2 x 2), whatever size you need. Make it simple as you need it to be.

Now, look at the paper from above, paper flat on the table or desk. Now slowly turn the paper 90° to the right. Repeat that until you have noted the 1st position of every element of the array, and it's last value, after the array is rotated.

<< THAT'S how you learn to solve a problem. >>

If you use a different value for every element of the array, it may help you.

Write down the equation that solves the change in position for any element, after the array has been rotated, given it's starting position. It's simple arithmetic, so no trig or calc is necessary, here.

Doing it this way, you WILL LEARN and remember, how this works, for a very long time. If I just told you, you'd forget it inside of a week.

And have fun, because this is a fun exercise. ;)

Adak 419 Nearly a Posting Virtuoso

Welcome to the forum -- but if you don't show some work toward your query, you won't get help (99% of the time).

That's a "rule" in most programming forums, btw. Otherwise, we become a free homework service, while you party on.

You see the problem, yes?

Adak 419 Nearly a Posting Virtuoso

Your indentation is horrid, of course. I believe your problem is that the scanf(), for a char especially, is troublesome, because scanf() always leaves the newline behind (when the user hits enter a newline is sent to the input buffer, as well as the keystroke he hits).

To remove the newline, add a getchar(), (or use any other means you want), to pull the newline off the input buffer. For multiple input problems, use the getchar() in a while loop, and pull off all the input char's until the char is a '\n' (a newline). That will be the last char, normally.

while((charVariable=getchar()) != '\n');

Note the semi-colon - this is a one line while loop.

Since the newline isn't seen, this always trips up beginners who rely on scanf() for user input. Another example of this can be seen where you have a do while(intVariable != 0), loop, which maybe shows a menu repeatedly. If you have no getchar(), and the user enters a single letter instead of a number -- well, it's not pretty. Try it. ;)

Adak 419 Nearly a Posting Virtuoso

I'm not sure what the Dietal book presented, so let me recommend the bible of C, "The C Programming Language", second edition, by Kernighan and Ritchie.

This is the "heart" of C, by two of the developers of it. It's excellent, and definitely "meaty", in a good way. Although none-too-fat, it is not for "dabblers". Be sure to work through the exercises at the end of each chapter. This material is available on line, Google it. Also available are the answers to the exercises, iirc.

The next step is Algorithms and Data structures, and practicing solving real life exercise problems, with C. I don't mean full production code, but programs that show you know how to find and use a suitable algorithm and data structures, for the problem.

Work with a simple problem, say you have 10 names, and you need them in two orders for your reports: 1) Sorted alphabetically, and 2) in their original order. Your job is to make this available as quickly as possible, as part of a much larger program. Now:

1) what sorting algorithm would you use?
2) if the names need to be shown first in sorted order, and later in their original order, how would you do that? (yes, it's a trick question, so think tricky).

Now your boss comes in and says instead of 10 names, your functions should handle 10,000 names, optimized still of course. Redo it.

(You can download long lists of …

Adak 419 Nearly a Posting Virtuoso

Tubby, Salem is one of the most prolific C repliers on the C forums. What he's talking about is that people post the same info on several boards. Then people like him answer them, ON EACH OF THE SEVERAL BOARDS.

That means there's a tremendous amount of duplicated work, especially when the original poster has a boatload of follow up questions.

We've seen where the answers were 2-3 pages deep, on 4 forums. The problem is, people do this as a donation to the community, but there is limited time available. Multiple forum requests (I'm referring to those made on the same day, with the same content), waste that resource.

Adak 419 Nearly a Posting Virtuoso

Muthmuth, it's far better if you:

1) Wait until the poster has made at least one solid attempt to write the code themselves, before you write code for them.

2) Use code tags around your code, ALWAYS. Just highlight your code and click on the [ CODE] icon at the top of the editor window, and it's done.

Appreciate your enthusiasm, and welcome to the forum, Muthmuth. ;)

Adak 419 Nearly a Posting Virtuoso

Build an index array of int's. After initializing the index[], 0-RowNum-1, Sort the index int's, according to how many matching words are on each line.

Although the data will not be moved, you can now print up the rows, ascending or descending, ranked by how many words matched in that row, using Rows[index].

Ever sorted by using an index[] array? It's a bit like magic when you first see it.

Adak 419 Nearly a Posting Virtuoso

Post up a short example of your problem, that I can run, and let's see what the details are.

Adak 419 Nearly a Posting Virtuoso

In my class (all one of them), the instructor taught us to use the Top Down design method. In a nutshell:

1) Study the problem, better than you believe you need to
2) Put off all the details you can, for now.
3) On paper, note the functional separations you'll need, probably:

a) Input
b) processing
c) Output
etc.
4) Note the parameters each functional part will need to work with, and make rough functions in code. Just reasonably close for now, and pseudo code or plain language, is fine.

5) Check that you have all the big parts of the program, included.

6) Start with main(), and work with each function in the order the program will, and start replacing the plain language and pseudo code, with actual code. All the details that you can put off still, put off. Only the essentials right now.

7) Once you have the flow of the program down right, go back and get enough details that the accuracy of your calculations can be confirmed. Things like appearance are still being put off. This applies to all functions except those dealing with appearance and other details.

8) When the above is OK, then get into all the details that you put off. NOW is the time to make your output, really shine.

The advantage is that the important things are done first, and the numerous lines of code dedicated to …

Adak 419 Nearly a Posting Virtuoso

You're welcome.

Adak 419 Nearly a Posting Virtuoso

You could have fixed length structs (records), which are normally written out in binary mode, and read in as binary data, using fwrite(). For structs of varying length, (where any member of the struct might have a varying length), the advantages of binary mode just fade away, and they should be written out as text, (using fprintf), and read in as text as well.

Here, you should not be rewinding your fp after you close the file, and fgets() is used for text, not binary, data.

Either use fread() and fwrite(), (binary mode) or use fgets() and sscanf(), along with fprintf(), in text mode. Don't mix the two.

Adak 419 Nearly a Posting Virtuoso

Have you considered using strstr()? It's made for this, imo. Look at it in your help file, and see what you think.

Then make a little test case and program, with strstr(), or with your earlier idea, or both, and see how it works. You know you're close, so it won't be a waste of time. Be sure the test case has some "difficult" text, which includes most or all of the above details discussed herein.

There's always more than one way to do something. If I have a very small number of words, I tend to use a small buffer, and go char by char (ie., small), to do this. If I have a lot of text, then I tend to go with a very big buffer, and use strstr(). I believe you should know how to use either one, depending on what you think is best, at that time, for that problem.

Adak 419 Nearly a Posting Virtuoso

What I'd recommend is DON'T write it up to the line printer, directly.

Instead, print it to the screen, once you know the top left and bottom right of the printable area of your printer.
Enumerate your rows and columns:

XX1234567890123456789012345678901234567890  << row just before the first printable row
X1.......................................X << First printable row
X2.......................................X
X3.......................................X
X4.......................................X << row numbers
X5.......................................X
X6.......................................X
X7.......................................X
X8.......................................X
X9.......................................X
10.......................................X
11.......................................X
12.......................................X
13.......................................X
14.......................................X
15.......................................X << Last printable row
XX12345678901234567890123456789012345678901234567890 << Column enumeration numbers

X or a digit = a position that your printer can't print in.

Naturally, you want to set your printer up for the widest and tallest print area, that you can.

When it looks right, then print it. Probably by writing it to a text file,and then printing it with Linux, for right now. How many of these sheets do you have to print up?

Once you have the pages printed to file, you can easily print them up with Linux, using Ubuntu. I'm not sure how you print directly in Linux, but I'm sure the Ubuntu Forum (which is VERY active and good), can tell us. :)

BlackJavaBean commented: Very well written and to the point. Extremely helpful! +2
Adak 419 Nearly a Posting Virtuoso

You don't need to post up the whole program, just post up the smallest example of the problem you're having, in a snippet of code that runs and shows the problem.

Sometimes, the doctor must actually examine the patient. ;)

Adak 419 Nearly a Posting Virtuoso

You can do it that way, but the last index number will always refer to a letter in a word.

In a virtual way, you've reduced the list of words to a list of a list, of words. So array[row][wordNum] is what you will use with strcmp(), to see if the word is a repeat or not.

if((strcmp(array[row][0], array[row][1])) == 0) {
  //it's a matching name
}

Put the above inside a loop, where row and word numbers are variables.

For strcmp() to work, you need two things:

1) to include string.h into the program, and

2) every word must be a true string, ending with an end of string char, which it appears you have.

Adak 419 Nearly a Posting Virtuoso

Whether you do this in Linux or Windows, the logic is about the same.

The page is a perfect representation of a 2D char array. You need to print out a test sheet to discover:

1) What is the top left char that can be printed by the printer

2) What is the bottom right char that the printer can print

top left is obviously, 2d[0][0], and you work down the rows (and over the columns), from that point.

Now you can print out your data into a plain text file, and by all means, print up a temporary row and number counter, to help you know how far to move your output around.

Now pick out the char from your ASCII (or other) character set, that most closely matches the size of the marks you want to make, on your printed page. An ASCII chart downloaded from the net would be quite valuable for this (your own systems character set values may differ in some char's, but most will be the same). You can even print up your own character set values.

And with that, you can start designing your output. Be sure to display the page, with a close representation of it in a console window first, otherwise you'll waste a TON of paper and time.

I've done this in DOS and Windows, with similar requirements, but not in Linux. Since you're using just console text however, it should be …

Adak 419 Nearly a Posting Virtuoso

Good! Now tell me when you know that the word to replace, has ended?

1) a space is reached, obviously ;)

2) an end of line char is reached, of course

3) what about EOF (end of file), and punctuation char's?

Lots of details when you deal with strings, language, etc. Great start though.

Adak 419 Nearly a Posting Virtuoso

Computers don't really do anything with char's - they're just numbers with a different value, so the computer can tell them apart. Those values vary depending on your systems character set, but most use values equal or close to, the ASCII set or table values. You should d/l one if you program.

In a typical character set, 0 is 48, and since they (the digits 0 through 9), are in sequence in the character set, the char digit, minus '0' (the char zero), equals the value of the number.

Adak 419 Nearly a Posting Virtuoso

The problem is at some distance before they pass (at t2) they will have sufficient velocity to pass each other on the next iteration (t3). At t3 the distance will not be the same as t2 causing the deceleration to be different.

You may not care what the velocity is. The fact that the particles have not actually reached that mid point, is what counts. That should be the correct t2.

Note that I am NOT a physics guy, however. Seems like common sense.

Adak 419 Nearly a Posting Virtuoso

Using a basic for or while loop, perhaps:

set i and j to zero
while(i is less than 12) {
  a[j]= index[i++]; 
  b[j] = index[i++];
  ... etc.
  j++;
}
Adak 419 Nearly a Posting Virtuoso

Thank you for your response

I was not talking about the windows help system. I mentioned the HTML Help Workshop 1.4 as a software i would like to open the directory with. It is a software used to open/read some e-books. The directory should be static HTML page or application.

If i were to use DB2 or Oracle Database, is it possible to make the directory look like an e-book which could be opened with HTML Help Workshop?

Once more, thank you very much.

You might be thinking of DB2 or Oracle Database, or HTML Help Workshop 1.4 as helpful things to ease the process of making this phone directory, but I disagree. All these things are helpful ONLY if you know how to use them already, which i believe, you do not know.

Therefore, they are going to be obstacles, rather than things that will help you.

The first thing is to study the problem in greater detail. It's one thing to make a telephone directory for less than 100,000 people, and quite another thing to make a directory for 20 million people or more. Scale is important. What is right for one size, will be wrong for another size scale.

Next thing is on line access. How many times a day will this system need to be accessed? Approximately how many updates will need to be done per day? Again, scale is important.

Using C or C++ seems a natural because they are both …

Adak 419 Nearly a Posting Virtuoso

"Each column should then become a column matrix." ??

Your description of the problem is quite poor. SHOW the input, SHOW the output you need and any special set up your problem requires. Do not rely on describing the problem. You suck at that, clearly. ;)

Forget your code, for now. Until we understand WHAT you're trying to do very clearly, your code is just a nuisance.

What AD is suggesting is this - get all your data into a buffer first, then it can be manipulated as necessary, from that point, step by step. What those steps should be, we still don't know.

Adak 419 Nearly a Posting Virtuoso

Hello guys! i really need your help.

In my program, I am reading the contents of the file.

File looks like this:

1 ART ACE APE
2 BAT BOY
3 CAT COP CUP CAP CUT

I want to store the words in an array. one array per line.

I just would like to ask how do you separate the number from the words when reading from the file? And how will the computer know that it is already going to a new line, thus must fill the next array. Knowing when the next line starts troubles me because each line could have any number of words, max of 8 words per line.

I have been thinking of these for the past three days,

and so far this is what I got,
i know this is short but with this code, I already get a segmentation fault. i don't know why.

Please, help me.

int main() {

	FILE *ifp, *ofp;

	ofp = fopen("input.txt", "a");

	ifp = fopen("output.txt", "r");

	char data[8][8][3];
	int a,b,z;
	for (a=0; a<20; a++)
		for (b=0;b<20; b++)
			for (z=0; z<3; z++)
				data[a][b][z] = ' '; 

	char number[20];



	char c;

	while ((c = getc(ifp)) != EOF) {
	printf(c); // i did this to check if it is successful reading
	}
	
	
}

please shed some light. thank you very much.

Generally speaking (since I don't know the specifics of what you're trying to do), you want to have one word per line, in a two dimension array.

The key is the …

Adak 419 Nearly a Posting Virtuoso

Welcome to the forum, Dharma. :)

Two suggestions for your study in C:

1) for technical reasons, C should always have an int return from main. The correct format for main in these programs would be:

int main(void)

with

return 0; at the end of main.

I know void is taught sometimes, and shown in books, but that is wrong, and support for it may not continue in the future.

2) variable names like i,j,k,a,n, etc., are all good, but in this program, and in your programs in the future, it's a huge help to use descriptive variable names like row, rowNum, column or columnNum, etc. We all "get" and use i and j quite commonly, but the rest of those names - well, they could be improved.

Right now, I'm re-writing a program I wrote some years back (expanding it and upgrading it to 64 bit format), and it's a BIG help to have descriptive names for most of the variables where the purpose of it is not easily remembered years later.

arindam31 commented: That was great suggestion.....Ill try to follow these from now on... +0
Adak 419 Nearly a Posting Virtuoso

group the numbers in the file into 7

Into 7 what, seven columns per row, seven rows, seven digits per column, seven digits per row?

Show an example: Input, and what you need for your array. Your description leaves a lot to be desired. An example would serve much better.

Adak 419 Nearly a Posting Virtuoso

I really like the way you're thinking on this! Well done.

fgets() is what you want, but you're quite right that fgets() has to go char by char (at a very low and fast level), to find the end of each row of text.

It is NOT the same thing as scanning, like getchar(), because there is no conversion going on, but still, it is a char by char check for that newline char. There's nothing you can do about that. Any other function you could use, would still have to make that check to see if the next char was a semi-colon.

Having fgets() put each line of text into the same buffer array is the right way to go, the address of the buffer is kept in cache, thus accessed very quickly. You should be using a while or for loop for this, something like:

while((fgets(arrayName, 100, filePointer)) != NULL) {
   if(*arrayName == ';') {
      handle that here. Array already has the text you need
      to work with.
   }
}

No "else" is needed, because you're using the loop logic, itself. It's concise, clean and fast.

Adak 419 Nearly a Posting Virtuoso

The filename variable fName, needs to be a char array, not an int.

Adak 419 Nearly a Posting Virtuoso

It should be obvious by now that this exercise requires SOME type of looping. Recursion is just a different way of looping.

Whether the looping works with the program code, (in whatever logic), the operating system, or even the underlying hardware, it makes no difference in terms of the logic. You can either write out the individual increments, one by one, or you will use some type of looping.

It's a great exercise for fun perhaps, but as far as teaching you something about C, it has minimal benefit, imo.

Adak 419 Nearly a Posting Virtuoso

Line 41 - C'mon, you're not ready to open anything yet. You have to get the filename first. Delete this line.

Line 44 - You can't use a char array variable, without first declaring it. Declare fName first, then use it. (and don't make it too small).

Line 45 - No capital F in fopen. C is always case sensitive.

If the function should return an int, then you need to return an int, don't you?

Work with this, you can do much better than this. Work on the overall flow first, and put off the details for later. Check your syntax (try to compile it), when you have made changes, so you're polishing your syntax as you move along.

You never want to be left with dozens of errors and no idea where the error that caused it all, might be.

Adak 419 Nearly a Posting Virtuoso

It isn't clear what you want, but what is clear is:

1) You need to learn some basics before you start programming in C. Run through some of the many tutorials that are on-line, or study and practice from a book.

2) Unless you are required to use Turbo C, switch. I love Turbo C, and have used it for decades, but it's time has come and gone. It's now as much of a detriment to your progress in C, as it is a benefit to it.

That ball, it keeps on bouncing...

Adak 419 Nearly a Posting Virtuoso

Think about the flow of the program, and work it through with paper and pencil first.

Open the file, read the contents line by line with fgets(), until you reach the words to be replaced. All the lines are being written out to a second filename.

Acquire the new word that you will be adding, and put it into the char array you are using to hold the row of text with fgets(), at the correct position. Make any char adjustments that you need to make in the row of text now. (maybe the new word is longer or shorter than the old word).

Write out the new line of text to the temp file, and continue reading and writing the lines of text, until you have no more data.

Kill the old filename, and name the temp filename to the old filename.

This isn't "hello world" easy, but if you take it step by step, and visualize where the current position of the file pointer is as you are doing the replacement, it's not as difficult as it sounds.

If you need it coded up urgently, I suggest you simply hire someone to do it for you. C is not a language you get good at, overnight.

Adak 419 Nearly a Posting Virtuoso

Windows has always allowed programs to use the various ports and keyboard input. Can you do it without working through Windows on Win98 SE, -- I'm not sure.

If you're thinking about making a keylogger, stop right there. They have a serious risk of being misused - whether it's by you, or by someone else who stumbles upon the program. They have very little reason to exist that is not illegal, or immoral, and no one here will help you code one up. "Just to see if I can... just to study how it works...just to learn more about the system... NONE OF IT sounds credible in the least.

Give up on the keylogger idea, as fast as you can. They are nothing but trouble, even if you are a saint and would not abuse it -- because others would hear about it, or stumble across it, copy it, and then THEY would abuse it.

Adak 419 Nearly a Posting Virtuoso

@Soubhik This is not programming!

This is the right hand reaching for a knife to fight off an alligator, while your left hand is is running a chemical analysis of the water in the swamp.

It's nuts, but it can be fun, and some of the obfuscated code is A) hilarious, and B) very creative.

go to http://www0.us.ioccc.org/main.html
and get some of their past champs - they're a laugh riot and a creative marvel. But they're sure NOT any kind of serious code. No way. ;)

Adak 419 Nearly a Posting Virtuoso

<< White space like tabs, and newlines, don't count >>

I can help you to find a couple on Google, but I can't help you learn what they're doing - I simply don't code that way, and have no intention to start studying to program that way.

Life is short, so make sure what you are doing is worth your time.

Anyway, this is the famous obfuscated contest web site, that was already mentioned:

http://www.ioccc.org/

and this is one example of a problem, and the road to a winning solution:

http://home.datacomm.ch/t_wolf/tw/misc/contest.html

Note how the definition of what is and is not allowed, becomes all important. If you don't know the standard that they're following for the rules of the contest VERY well, you could easily waste a good deal of time.

Adak 419 Nearly a Posting Virtuoso

It seems obvious that there is such code - look at the shorter programs to verify that.

I don't know any way to shorten that up, but I'm thinking it must be done with a completely different algorithm. What that is, I have no clue.

The problem with it is, if you were to make the very smallest code possible, your boss would tell you to NEVER code like that, again. ;)

It's great having a short function or program, but if it's hard to understand - cryptic or overly clever, then it's a nightmare to have to maintain or extend (as is so very common).

There are websites that specialize in this kind of code, so studying and asking this question there, would be helpful. After this amount of time, I believe everyone here who has an interest in this (even a slight interest), has already given your their best idea.

Adak 419 Nearly a Posting Virtuoso

It's not that difficult. We just have to change the code a bit to make it work this way.

Why don't you post up the first ten lines of text from the dictionary file, and I'll show you how it can be done? Same format and everything.

Tinkering with code, is not a bad thing.

Adak 419 Nearly a Posting Virtuoso

First, use code tags around your program's code. Nobody wants to study code that looks like the dog's dinner, two days ago. ;)

Second, narrow it down. WHAT do you need help with? Are you getting the mean calculated OK?

Narrow down what we should focus on, and save us all a lot of time. You'd be amazed at the pure genius we see in noobs, with messing up a program!

And no matter how badly you want to avoid it, you WILL have to learn some troubleshooting techniques - and practice them. Your programs will initially have bugs, and you will have to hunt them down.

So what about the mean? Is that good?

Adak 419 Nearly a Posting Virtuoso

You don't need the Pearl script at all. Do you have the dictionary file yet?

Forget the Pearl script, get the dictionary file, and take just copy the first 10 words of so, out, for a test file.

Now, what problems do you have?

Adak 419 Nearly a Posting Virtuoso

This is a sample of your code, put into a program. It works fine. Note that after writing out the data (which is being done at the end of the file in this case), it's necessary to have a rewind() in there (or some other reset of the file pointer), to return the file pointer to the start of the file again.

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

struct item
{
  int item_no;
  char item_name[20];
  float rate;
}i1;

int main(void)
{
  FILE *fp = fopen("test2.txt","rw+");
  i1.item_no=101;
  strcpy(i1.item_name, "Mobile");
  i1.rate=5000.00;
  if(fp==NULL) {
    printf("Error opening file\n");
    return 1;
  }
  fprintf(fp,"%d,%-20s,%.2f\n",i1.item_no,i1.item_name,i1.rate);
  printf("%d,%-20s,%.2f\n",i1.item_no,i1.item_name,i1.rate);
  rewind(fp);
  printf("\nThe data has now been written to the file\n");
  getchar();
  fscanf(fp,"%d%*c %s%*c %f",&i1.item_no,i1.item_name,&i1.rate);
  printf("%d %s %.2f\n",i1.item_no,i1.item_name,i1.rate);
  printf("\n This is the data that was read from the file\n");
  fclose(fp);
  return 0;
}

If you'll post your code with code tags around it, I will read it more carefully than last time. I expected fully that you would be reading from the file, before you wrote data to it. ;)

Adak 419 Nearly a Posting Virtuoso

.2 is an output format specification. You are using it in your input format specification for the float.

Adak 419 Nearly a Posting Virtuoso

Turbo C and Dev C are OK for small exercises, but Dev C is no longer supported (hasn't been for some years now), and Turbo C is 16 bit, which is very limiting for it's data sizes. Also, far pointers in TC are not possible (the memory model is all flat now), and several new features to the language have been added.

I love Turbo C, and still use it for small puzzles, but for anything serious, use either Microsoft Visual Express (free), and give your c programs a c filename extension (dot cpp for C++). It also has an extensive video you can d/l to show you how to get started with it - be sure to get it.

My suggestion is the delightful Pelles C IDE and compiler - everything is C only, and Windows (32 or 64 bit), and absolutely wonderful in it's simple but powerful layout of the IDE. It's also free. Google it up - and check out it's forum, while you're there.

Using either of these, you're up to date with C - with the others, you're WAY obsolete. I love(ed) Turbo C, but it's 20 years behind the times!

Adak 419 Nearly a Posting Virtuoso

In my very limited experience with these kinds of programs, they love to explore the limits - and frequently venture outside the limits of modern C, into a deprecated version that won't compile at all on any modern compiler (even turbo C).

In the above program, you haven't defined the data type for the s, n, or t variables. Even though a compiler might accept it as OK, the standard for C would not allow it - making it "undefined behavior". (which means it might run on your compiler, but it might not run, or might produce the wrong results, on another standard C compiler).

Did you try compiling and running this program? On what compiler?

Some obfuscated programs are really legal and quite ingenious and short. Others are outrageous crap that will crash on 95% of the systems and compilers.

Only by testing them sometimes, can you tell which is which.

Adak 419 Nearly a Posting Virtuoso

Two chars less:

#define X scanf("%d",&
main(){
  int n,s=0,t;X t);
  for(;t--;){
    X n);
    n>0?s+=n:0;
  }
  printf("%d",s);
  return 0;
}

I tried some other ways of doing this. This was the best I came up with, so far.;)

Now I'm curious what they have in the smallest programs.