http://cboard.cprogramming.com/c-programming/134849-do-while-problem.html
Same user name, same title, same time frame.
http://cboard.cprogramming.com/c-programming/134849-do-while-problem.html
Same user name, same title, same time frame.
Please don't immediately cross post your question on multiple boards.
This has already been answered "over there". :(
I believe you are laboring under a very poor concept here. You do NOT NOT NOT want to mess with the "inner" workings of a proven cryptology program.
It works -- leave it alone.;)
Treat each part of it (encryption and decryption), as "black boxes", and code up function logic around them (like a wrapper around a sandwich - it doesn't disturb the contents of the sandwich in any way).
The NIST studied several candidates for their new crypto program, and have put a lot of info on their relative performance, into a PDF you can download from their website.
With that in mind, I don't see your problem: you have the code you need for the crypto program, except how you want to combine the two functions, into one.
I answered that question: you use a parameter value that you will pass when you call the crypto function. That will decide whether the text you're also passing (or file), will be encrypted, or decrypted.
Good crypto programs are fine pieces of logic, and have to be extensively (very extensively) worked out by the creators, and tested. If you change just one piece of the "inner" logic, you may easily ruin it, AND you probably won't know it without a huge amount of testing, by experts in the field.
In conclusion, don't mess with the inner workings of the crypto program. Use it, and make any "wrapper" type handling function for it, that …
Let's be clear - you can NOT run a graphics program from Turbo C, in your compiler. It's not a matter of C, it's a matter of support for and inclusion of the graphics.h file. Your compiler doesn't have it, and nobody else uses Turbo C's graphics header files (that I know of, and I've been using Turbo C for since the early 1990's).
You will have to use a graphics library or header, that's compatible with your compiler. Or download Turbo C and use it (from the Borland legacy program site).
The best way to start a program, is frequently to work it through by hand, on paper. How would you do this, without a computer?
You might use a row of an order form, where columns denoted the features the order desk should have, with a sub-total of the price on the far right hand or lower part of the form.
Using a struct with members for these features, seems a natural, but parallel arrays or even individual variables, can be used, as well.
Once you REALLY understand the problem, and can break it down into simple, small steps of logic, THEN you're ready to put those simple steps, into pseudo code.
If() statements for the features, seems like a step in the right direction.
Some (newer standard) C compilers will allow variables to be declared throughout a function.
But the old standard wouldn't allow it. Move int i, up to the rest of the variables you have declared for main(), and re-try.
det is a single char. You're trying to make it a string, and it can never be a string, since it has no room for an end of string char '\0' to go on the end of it.
Try calling it with an int array A[], where lo is zero, and hi is the top of the array (the index, not the value it holds).
It does the same thing as your program, but more concisely. Yours used a pointer *p where this one uses a variable val (for value). More to the point, it uses just one pair of nested loops, to do everything. It is quick, especially for small and mid sized number of items (say to 100 or 200), particularly so when the items are almost already sorted - then it blazes!
I use it to speed up Quicksort, when the sub arrays Quicksort is working with, become small enough. Insertion sort, finishes them off - very nice. Also, any small to medium sized sorting job. Much faster than bubble sort, trust me! ;)
So post your code (and do paste it between the code tags you get by clicking on the icon in the editor), and tell us what has you stumped. [/B][code ] icon in the editor), and tell us what has you stumped.
Your code is very verbose, and overly complex. Try and keep it short, simpler, and thus faster. Like this:
void insertionSort(int A[], int lo, int hi) {
int i, j, val;
for(i=lo+1;i<hi;i++) {
val = A[i];
j = i-1;
while(A[j] > val) {
A[j + 1] = A[j];
--j;
if(j<0) break;
}
A[j+1] = val;
}
puts("\nAfter Insertion Sort:\n");
for(i=lo;i<hi;i++)
printf(" %2d ",A[i]);
getch();
}
The way this forum works is that YOU are responsible for posting up your try to solve the assignment/exercise.
So post your code (and do paste it between the code tags you get by clicking on icon in the editor), and tell us what has you stumped.
Regarding reversing a word, first, you need to ID the word - where does it start, and where does it stop, if there are other words next to it.
Then, practice it by hand yourself, and try to recognize the basic steps you use to do this task. Those simple step by step instructions, will be the backbone of your programs logic, if they're small enough steps.[code ] icon in the editor), and tell us what has you stumped.
Regarding reversing a word, first, you need to ID the word - where does it start, and where does it stop, if there are other words next to it.
Then, practice it by hand yourself, and try to recognize the basic steps you use to do this task. Those simple step by step instructions, will be the backbone of your programs logic, if they're small enough steps.
Turbo C, as was mentioned just above, has a very unique graphics ability. You can't duplicate it in another compiler, (in anything like a realistic amount of time and effort).
So you can use this clock code as something to study and learn from, but you can't fix those errors and run it, in graphics mode, without Turbo C.
My suggestion is to make a digital clock in a console window, first. Then work to understand the graphics that you need to use to display an analog clock, in a modern window, with modern graphics.
All in a timely manner, of course! ;)
I know two verses of a song (in a function), but I need someone (another function), to tell me which one to start singing.
How could that be done?
Have you ever heard of PARAMETER City? Lovely place. Post up your map and bring your compass, and we'll get you there.
if(you want to visit the museum) (parameter type is 1, so encrypt)
arrive on a Saturday (encrypt)
else
arrive on a Monday for best room rates (decrypt)
I love the travel industry. ;)
The struct members (aka fields), are just the same thing as variables:
int myVariable = 0;
mystructName.myStructVariable = 0; //or = any int variable you have
if myStructVariable is an int, and a member of the struct called mystructName, then the above assignments are the same.
You can use scanf("%d", &mystructName.myStructVariable), same as any other integer. You can string copy into struct members that are char arrays or pointers to same.
The main difference with using a struct is that access is through the dot operator: structName.structMember.
num[] is a global array, so bubble function can access it already. Don't pass num[] to the bubble function.
BUT length is not a global, and you need to declare it as an int, in main() so it can be passed to bubble function. Give it the number of floats in num[], or it's useless.
So your bubble prototype is:
void bubble(int);
Your call to bubble is:
bubble(length);
and your bubble first line declaration is the same as your prototype, but ends with a curly brace, instead of a semi-colon, and includes the name of the int, length:
void bubble(int length) { //NO semi-colon here!
Tom, you need to study up. These are VERY basic concepts here. Work at it! ;)
Might be best if you started a new thread, but I'll leave that decision up to you.
What is the error that the compiler is giving you? Turbo C is probably a bit different with some of it's macro's, and headers.
There are four arrow keys. Each gives two bytes, the first one is 0 or 0x00 in hex.
The second byte determines which arrow key: 0x48, 0x4b, 0x4d, 0x50
for up, left, right and down, respectively.
You should download an ASCII char and key scan code chart, if you don't have one.
In main() you MUST call the bubble() function, if you want the program to use that function and sort.
Google has it:
This is a paper on Quark, which uses the Katan block cipher:
http://131002.net/quark/quark_full.pdf
This is a C program that implements it:
http://131002.net/quark/
This is a Linux program, so the free d/l Notepad light is good to view it, not Windows notepad (where the lines are horribly goofy. WinRAR, etc., will decompress, as will Linux distro's. (it's a tar.gz file.)
I haven't run into this one before, but it's a lightweight and fast hash block cipher. RFID apparently is a good use for it.
More Google stuff:
http://www.cs.technion.ac.il/~orrd/KATAN/
One = char is for assignment in C. Two == char's are used for comparisons.
if(variable == someValue);
This is the pseudo code for a nested loop version of bubble sort:
procedure bubbleSort( A : list of sortable items )
n = length(A)
for (i = 0; i < n; i++)
/* back through the area bringing smallest remaining element to position i */
for (j = n-1; j > i; j--)
if A[j-1] > A[j] then
swap(A[j-1], A[j])
end if
end for
end for
end procedure
Straight from Wikipedia, which has a whole page on it, and links to many more references, versions, etc.
My experience is with stepper motors, not servo's. Check your spec doc.
Imo, you need to logically lay out your code and data, for better control. Get a "flow", going, for the servo's, and more clarity in your code, for you. Call your other functions from your main control loops, but don't stick the low level stuff, into the high level loop. That's for you.
What I used were a few high level loops which were the loops I worked with to adjust the programming. Then there were low level functions that were called by the high level functions, that handled most of the speed and other details.
This was for an auto-dialer to open safes (when the department goof-offs had lost the combo), so long sequences were generated, and reliability was a must. No "epileptic squirrels" allowed. ;)
These servos sound like fun, but prone to herky-jerky. Stepper motors are prone to inadequate torque and to lie about completing their move. ;)
You've put in the wrong tags. For links, no tags are needed, can you fix it quickly?
After 30 minutes, you can't edit your post on the forum.
Welcome to the wonderful world of pointers/addresses running amok! ;)
Instead of using a number of arrays, I would use just one 2D array for the positions.
Servo 0 would have all it's positions in order, on row 0, cols 0 thru N
Servo 1 would have all it's positions in order, on row 1, cols 0 thru N
Servo 2 would have all it's positions in order, on row 2, cols 0 thru N
etc.
Now a nested pair of for loops
for(col = 0; col < N; col++) {
for(row = 0; row < 5; row++) {
//code to move a servo's in here using:
mov servo[row] to position[row][col] at speed[VarForSpeedHere]; //kind of stuff
}
}
See if that works. ;)
No, I haven't heard of that one, but Google and Wikipedia have a lot of information on all kinds of ciphers. Wikipedia has an entire portal dedicated to Cryptology - neat stuff.
With all the interest in protecting info these days, you should have no problem Googling successfully for it.
(Or do you already HAVE info on it and edging up the search engine optimization for that tag?) ;)
I answered this question for you, in the other forum.
Now that you're cross posting, I won't bother henceforth. You're wasting our time.
When you have several fields which all relate to the same object, you create a struct which will group the different fields (members of the struct), into one record (struct).
Then you use the dot member to access any member of the struct:
system.date
system.type
system.os
system.version
etc.
Which you will prototype right above main() so any function can make a local stuct for data it needs to work on.
struct system {
char date1[10];
char type[25];
float version;
int somevariableName;
//etc.
}
When you want to get a bunch of these together into an array, you simply create an array of structs:
struct system systems[SIZE];
Structs are a great thing, but be aware that the compiler will add a small amount of padding for alignment purposes, and not every compiler will pad them the same. That makes portability a real issue. Same compiler on a different system, may have different padding. ;)
Of course, you can sort the data according to any member of the struct.
You never assign a value to accountId. ;) ;)
What formatting works with printf(), will work with fprintf(), and the formatting that works with scanf(), will also work with fscanf(), and sscanf(), etc.
Nearly all of the printf() formats, also work the same in scanf().
There are a LOT of formats for each of these. The right format for your program, depends on exactly how you want your numbers to be formatted.
Try man scanf in your Linux terminal, or fscanf formats in Google, or the help file in your C ide.
printf("Enter 2-character state code: ");
scanf(" %c",&stateCode);
for(i = 0; i < NAME_LEN; ++i)
{
if (custArray[NAME_LEN].state == stateCode); //this is the line I am having a problem with
printCustArray(custArray[i]);
}
1) You're instruction say to enter a 2 char state code, but %c will only handle one char - and it's NOT going to make it into a string if you add two char's with a loop, still using %c.
Strings in C MUST have an end of string char at the end, and %c won't put it there.
%s WILL put it there. ;)
2) You need to use strcmp(string1, string2) == 0 to determine if strings are equal in C. (or roll your own strcompare function).
if((strcmp(string1, string2)) == 0)
{
do something in here
}
Is a standard idiom. You need to include string.h to use strcmp() (or have a smart compiler include it automatically for you).
Give that a shot. ;)
You can use a modified bubble sort if you make two changes:
When you find a char that needs to be swapped, you move the entire row of char's (the whole word).
Instead of comparing one column's char with the column next to it, like the regular bubble sort, you need to compare char's in the same column, but in adjacent rows.
IOW's, you "tilt" the array, over by 90 degrees, onto it's face, and make your comparisons, that way.
The sort through an index logic that WaltP mentioned above, is a great trick for any programmer to have in their toolbox, btw. It allows you to do some amazing tricks, since it keeps the original order of the input, yet allows you to SHOW the input, as if it was sorted, perfectly well (fast, too!).
Indexing is a powerful tool, any time you have a bunch of data, and need to organize it.
Computers and peripherals are address reliant - they must have them, or no go. It's no accident that all the operating systems (CPM, DOS, Linux, Windows, etc.), use addresses extensively. Pointers hold addresses, and are the only variables who do hold addresses.
Whether the language in question allows pointers or not for the user, you can be sure that the language itself is using them, to interface with the operating system or hardware.
How much pointers being used by the language, would help any particular peripheral device, depends on the system, the peripheral, the operating system, and what the program is doing.
Although pointers are powerful, they can also make code unbelievably difficult to understand and modify or debug, if over-used.
On older Windows (3.1 type), you need them, because it used the old 16 bit addressing memory mode.
With newer Windows, you will have to remove the far designation, or you'll get an error, even if you're using an older 16 bit, version of a compiler.
I use a very old version of Turbo C, which is 16 bit, in Windows XP. The far word must be removed or it crashes the program. (Yes, it will still compile, but it won't run).
C/C++ offers several advantages:
1) some free compilers, as well as competing commercial compilers, and a huge base of libraries. VB has none of these, that I know of.
2) a huge installed base of trained C/C++ programmers
3) there are a wide variety of compilers. One or more, for almost any device you can think of. VB has very few.
4) a C type program can be much smaller than a VB program, after compiling.
5) lots of good tools for the programmer in C/C++. Very few for VB.
Many data structures require the use of pointers to create them: linked lists, binary trees, circular buffers, etc. I don't believe there is any way to create these, in VB. (in some cases you can mimic them with arrays, but that's not the same)
In some specific tests, VB is probably just as fast as C/C++, before optimization. When you want/need more performance, you need the low level expertise that VB doesn't offer as a language. Indeed, mainframe programmers STILL rewrite critical portions of their application code, in optimized assembly code. For them, anything that isn't first rate in speed, is not going to be useful. If they had the time, they'd code up the whole program in assembly. Of course, that's impossible, but you get the idea - optimizing software is a BIG deal for their bottom line. VB is simply of no use for them.
VB is a fine language, …
If you're having problems with a do loop, you need to post up code that includes the do loop. ;)
Using CODE TAGS! <of course> Putting your code right between code tags, lets your code stay looking like code, and not like a dog's breakfast.
Shows a nice animation. Just showing off, I believe - ;)
So the advice that was given to NOT use gets(), and to USE code tags, was completely lost on you?
Try again. ;)
The earlier posts are from 2009, so I doubt they will answer your questions.
You need to start a new thread with your problem, and let this one be buried, again. ;)
I would ask this in one of the MS usenet groups (in newsgroups). This issue must be affecting others. Your answer may be there waiting for you, already.
In any case, you can get good answers, rather quickly there.
Good luck.
Just a repeat of the answer I gave to your post in the database section:
I would export this data, in text format, to a file. Then write a short program to make these changes. Then import the data back into Excel.
I don't know if you can do this in Excel easily, but it's trivial for a program to take your data, make these changes, and give it back to you.
You know how to export a file from Excel, in text format?
Do you know how to import a file back into Excel?
You don't REMOVE the line. The line should stay put.
The line has a full record, even if it's not visible for every field. (A string field of '\0' may show up as "", or may show up as nothing.
Use your debugger and see what's going on. Make sure you're printing out all the records, even the empty one's, to the file.
You should not be showing empty records on screen, normally, but they should be printed out to a file, for future use.
Sorry, yes. Use site[j].name[0] = '\0';
Zero's are better for the numbers, although '\0' is a zero, in char form.
You didn't show a return type for the prod() function. Also, you didn't add the prototype to the function, before main().
The prototype is just like the first line of the function, but doesn't need the name of the variables, just the type. Put that below the include files, before main().
Your compiler will WUVE YOU! ;) ;)
Seems to be the same error - datacode[] is an array of type char, so using %c in fscanf() for it, is an error or warning (at least). Also, the & in front of datacode, is wrong, since the name of the char array, serves as the address to the base of the array.
You should use %s for a string, IF the string is terminated by an end of string char: '\0'. If it's just a collection of letters, then it should be terminated either with a char to mark it (like a comma), or a space (white space).
It would be better to change it to this:
site[j].name = "";
site[j].city = "";
site[j].north = 0; //just plain zero for numbers
etc.
The thing is, you're NOT deleting a record, you're marking it as "deleted", and making it available for a complete overwrite by a new record that you add.
Your output (to the screen), should not show this kind of a deleted record, at all, unless you ask to show deleted records for some reason.
ALL records, including the deleted one's, are always written out to the data file, however.
Right off, there are no "string" data types in C. We use char array[sizeofArray];, instead.
Also, you need to use strcmp() to compare string in C. This
if(pos == string::npos)
Is an error for the compare, for the data type, and for the ::. There are no classes in C, and no ::
Try that and see if it looks better.
Looks like you have a "one off" error with i. If i was started at 0, then you need
j <= i in the for loop stop condition, instead of j < i.
Remember, you deleted record will have all the data as before, except the Name field will be look like "". The empty string.
You're not using the index number from find_site(). Are you supposed to use it?
What is the variable i holding for a value in delete_site()?
The phrase "C does not want to play ball", is not nearly as helpful in troubleshooting your program, as you seem to believe it is. ;)
Use your debugger or add some printf() statements in your code, and give us the real problem you're seeing with your program.
Oh of course! I thought it was just "dirty" input, but the hyphen has to be dealt with if it means "continue the numbers in series, from left to right".
When I deal with a string like this, that just isn't "quite right", the first thing I like to do, is make it "right".
char str[]="1,3,5-9,10,12-14";
One pass through a for loop would remove both the comma's, and replace the hyphens with a space. Then, use sscanf(), to get all the numbers.I don't have to move the end of string char.
And Welcome to the Forum, Aimbo! ;)