jephthah 1,888 Posting Maven

since you tried so hard, and i ran you around in circles, here's the fix:

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

int main(void)
{

const char *article[ 5 ] = {"the", "a", "one", "some", "any" }; 
const char *noun[ 5 ] = { "boy", "girl", "dog", "town", "car" };
const char *verb[ 5 ] = { "drove", "jumped", "ran", "walked", "skipped" };
const char *preposition [ 5 ] = { "to", "from", "over", "under", "on" };
char sentence[7][35] = {0};
int a=0, b=0, c=0, d=0, e=0, f=0;
int counter=0;

srand(time(NULL));

for (counter=1; counter <= 20; counter++)
{
    a = rand() % 5;   /*random numbers for each array of words */
    b = rand() % 5;
    c = rand() % 5;
    d = rand() % 5;
    e = rand() % 5;
    f = rand() % 5;
      
    strcpy(sentence[1], article[a]);
    strcpy(sentence[2], noun[b]);
    strcpy(sentence[3], verb[c]);
    strcpy(sentence[4], preposition[d]);
    strcpy(sentence[5], article[e]);
    strcpy(sentence[6], noun[f]);
    
    sentence[1][0] = toupper(sentence[1][0]);

    printf("%s %s %s %s %s %s.\n", sentence[1],
	sentence[2],sentence[3],sentence[4],
	sentence[5],sentence[6]);
}

printf("\n");

system("PAUSE");
return 0;
}
jephthah 1,888 Posting Maven

i just noticed you have defined your "sentence" array as pointer to "const char"... the "const" means that you can't change it. you'll want to define it as type "char"

a separate issue is that you have it as a pointer... if you're going to copy a string into it (and you will need to), then you need to lose the pointer and declare it as an array of strings. char sentence[7][35]; (i dont think you need 35 characters per word, since each of the "sentence" arrays is just a copied word... but thats a trivial point.

now you'll have to use "strcpy" to copy the word into the "sentence" array... you cant use assignment operators (= signs) to copy strings.

sorry i didnt see this earlier. :(


.

jephthah 1,888 Posting Maven

i would suggest that your problem is that you're on a Win32 OS, with hardware that was designed for a 32 bit OS, trying to use a 16-bit deprecated compiler along with an old MSDOS disassembler.

that you're having "problems" is no surprise.

i appreciate your offer for the compiler, and i thought about taking you up on it, but im afraid im going to have to pass.

for a moment i imagined it would be useful to help all those folks from the subcontinent who are forced to use Turbo C for gods-only-know-why... but then i come back to reality, and it really is the last thing i need to do, plus i would have to get all of Turbo C's non-ANSI deprecated libraries and all that, and honestly i just don't have time to deal with such antiquated stuff. I'd rather just sit on the sidelines and yell at them to join the 21st century. or hell, even join the mid-1990's.

but, thanks though.. and good luck. sorry, i dont know of any 16-bit compilers other than i might randomly find on google.


EDIT: To the Moderators... I think this DOES belong in the "Legacy Forum" as the OP originally placed it. He's obviously not getting much help here, other than pedantic ramblings.

jephthah 1,888 Posting Maven

sniper.... hm, i hope you're not really a sniper, because, well... i guess i'd just be sad a little bit... uh, never mind.

anyhow. check out my post in your other thread about 2D arrays, maybe it will help you.

jephthah 1,888 Posting Maven

a variable is like a box, that you can keep a single value in. say your array is a FLOAT type, and it's name is "temp". Therefore, in it you keep a floating point value of the temperature. and that's it

a simple (1-D) array is like a row of identical boxes, that you can keep a more than one value in, but one value per box. the name is still "temp" but now they have two "elements": "temp[0]" and "temp[1]" this could hold your "average low temperature" and your "average high temperature" respectively

a 2-D array is like many rows of identical boxes, divided in a grid-like pattern of rows and columns... now say you have 12 rows, and each row has 2 columns... the way you would define this array, at the top of your "main()" routine, is simply: float temp[12][2]; where the first index represents the "row" elements and can have index values from 0-11, while the second index represents the "column" elements , and can have index values of 0 or 1.

thus, temp[0][0] and temp[0][1] would be the average low and average high for the first month (January).

temp[1][0] and temp[1][1] would be the average low and average high for February

temp[2][0] and temp[2][1] would be the average low and average high for March

etc.

the point of this is so you can have variables representing the row and column... example:

printf("enter month (1=Jan ... 12=Dec) : …
jephthah 1,888 Posting Maven

MATLAB has 64-bit i/o support, via the "io64.h" library... ive never used it, but i've read people who said that it works well

http://matlab.izmiran.ru/help/techdoc/matlab_external/ch04cr16.html


.

jephthah 1,888 Posting Maven

at this point in your programming career, you should always use

#include <stdio.h>

the only time you should use

#include "myHeader.h"

is when you wrote that file (or someone gave it to you), and you saved it to the same directory as your C file.

jephthah 1,888 Posting Maven

well, actually, that's a terrible way to do it.

i guess partial credit is better than no credit, but i still dont understand why you didnt assign the output of "toupper" back into the array element from which you got it, in the first place?

what part of this didnt we explain?

jephthah 1,888 Posting Maven

i cant even get exe2bin to work on my Vista laptop. it's a native DOS application, for one thing.

what kind of hardware and OS are you running/compiling all this on? If you're trying to do 16-bit computing on modern machines, you're gonna have major difficulties.

i dont even trust EXE2BIN to work correctly, there's so many limitations of that program as it is, and now you want it to disassemble a third-party executable.

i think this approach (Turbo C + MSDOS Exe2Bin) is just doomed from the start.

jephthah 1,888 Posting Maven

sorry, man, i don't have Turbo C.

one time, i thought about installing it for fun, but they wanted a whole bunch of registration and personal info B.S.

which just reinforced the fact that i didn't want their crap on my hard drive, anyhow.

jephthah 1,888 Posting Maven

yeah, you did. good spot. :) ... by "we" i meant the various "veteran" forum members who have passed through this thread over the past week. (where's Salem, anyhow??)


(i think what happened here is everyone saw "Turbo C" and said PFFFT... or maybe we all got skeered by the assembly :P )


.

jephthah 1,888 Posting Maven

i can't for the life of me imagine why you would want to do such a thing.

but, admittedly, i'm getting old, and my neuronic sheaths are calcifiying....

jephthah 1,888 Posting Maven

wait a minute.... you're using "void main()" ?? LOL ... how did we not see this. You know, of course, "void main()" is undefined.

so it's no wonder you're having undefined behavior.

i dont think that borland would release a buggy compiler

oh, it was a great compiler.... in 1989. now its just full of deprecated, non-ANSI functions and terribly non-portable. Borland's strategic business plan appears to hinge on an exclusive distribution contract with the government of India, but other than that, i can't imagine why anyone would choose to use it.


.

jephthah 1,888 Posting Maven

my mistake: "toupper" is in the <ctype.h> library, not <string.h>

jephthah 1,888 Posting Maven

toupper returns the value of the character that is passed in as an argument, after it is operated upon.

value1 = toupper('a');
value2 = toupper('Z');
value3 = toupper('\n');

value1 is the only one that is different than the input. its value is 'A'. value2 and value3 are the same as the input ('Z' and '\n') since they are not uppercase characters.

so whatever the value returned is, just assign it back into the place from which you pulled the original character (the first letter)

consider the code fragment example:

char capitalizeMe[10] = "lowercase";

capitalizeMe[0]=toupper(capitalizeMe[0]);
capitalizeMe[5]=toupper(capitalizeMe[5]);

the result is that the word 'lowercase' is transformed to 'LowerCase'


.

jephthah 1,888 Posting Maven

if i have a character array, say: char myCharString[16]; and i want to capitalize the first letter (ie, the first element of the array), then I use the function "toupper" found in the <string.h> library, and it will do exactly what i want it to do: myCharString[0] = toupper(myCharString[0]); however... if your exercise prevents you from using <string.h> libaray functions, then you will need to convert it by hand.

first recall the ASCII code values of characters, and that a lowercase letter is exactly 32 (0x20) greater than its uppercase version, as designated by ASCII code. So to convert the lowercase 'a' (0x61 in ASCII) to 'A' (0x41) you would subtract 0x20 from the former (or 32 decimal, if you prefer), like so: myCharString[0] -= 0x20; however, doing this by hand has its dangers. you will have to FIRST CONFIRM that the character is indeed both a lowercase letter (and not anything otherwise), else the result of subtracting 0x20 from some other character can easily crash your program.


EDIT: One thing to remember the type char is, for all intents and purposes, an 8-bit int. char and int can be operated upon in the same way with the only exception being that int is generally 32 bits.


.

jephthah 1,888 Posting Maven

except that case 'n': should be case '\n': a simple typo, of course, but one that could drive a beginner to pull their hair out.

just sayin'.

mitrmkar commented: well spotted ... thanks +3
jephthah 1,888 Posting Maven

true.

i found that i often did my best when, even though I felt completely unprepared, i just said F- it and went to bed instead of pulling an all-nighter.

jephthah 1,888 Posting Maven

What cramming does is pump knowledge into shortterm memory without imprinting it in longterm memory.
What that means is that the knowledge will be there "at the top of your brain" for 24-48 hours after which it will be gone again.

aha. so that's where my Signals and Systems class went...

jephthah 1,888 Posting Maven

you're probably right. t'was just a suggestion.

jephthah 1,888 Posting Maven

not an appropriate question for a c-language forum. this is not a c-code problem --the code obviously works as designed.

your problem is an IDE problem, and not one that is commonly used.

the fact that an open source IDE isnt working for you the way you expect it to is about par for the course. you need to go to Eclipse tech forums and find out what you're configuring incorrectly.

why dont you just continue to use the make file to rebuild your changes? seems like less work to me.

---

cool icon by the way :)


.

jephthah 1,888 Posting Maven

the short answer is because your loop, "while ... getchar" is also getting, and processing, the newline character

one thing to consider though, is "what if" the person enters more than one character ...

DRAGON's example of just a single "getchar" will not handle that... to do so, you would need to replace the single "getchar" within each case statement with something like: do { flush = getchar(); } while (flush && flush != '\n'); .

jephthah 1,888 Posting Maven

whatever happened to actually learning and understanding what you're supposed to know rather than waiting for the last minute to cram for the exam?

really? last minute cramming is the tried and true method. I'm quite sure it pre-dates the Neolithic Era. At any rate, it's how i got my degree :P


.

jephthah 1,888 Posting Maven

hi. Paolo. i wish i had an answer for you. i would try, but i don't have the compiler to replicate it with.

well, i can see now you're not the typical Turbo C user who just doesn't know any better. ... so if you don't mind, i'd like to know why do you need to use it? curious.

jephthah 1,888 Posting Maven

you got a lot of errors, but i see what you're trying to do. so at least you're on track. :) here's a few of the more obvious problems:

(1) all variables should be declared before using them. I suggest that you declare the array "x" at the start of your "main" routine like so : int x[100]; ... this means of course that you are limited to a max of 100 values. change the number if you want. you should probably make a corresponding check that the user doesnt try to exceed this maximum value.

Dragon suggested "malloc"... definitely an option, but it is a more advanced concept and can get you in trouble later down the road if you dont fully understand it's power. Also, if this is homework, your grader will become very suspicious of you using advanced memory allocation functions when you dont have a grasp of the fundamentals.

(2) declaring variables again. i see you have the variable "operation" which is neither declared nor initialized. declare "operation" at the top of main like so: int operation; (3) to use a switch statement, you have to switch on a variable that has been set. "operation" has not been set. I assume here is where you wanted to use your "#define MULTIPLY 1"

printf("enter 1 to multiply or 2 to divide: ");
scanf("%d",&operation);

switch(operation)
{
    case MULTIPLY:
    ...
    break;
 
    case DIVIDE:
    ...
    break;

    ... etc ...

    default:
        printf("not a valid operation!\n");
}

this …

jephthah 1,888 Posting Maven

turbo C is a piece of crap.

use the GCC compiler (free) or MSVC compiler (free) with the Code::Blocks IDE (free).

jephthah 1,888 Posting Maven

good job. you must be happy you stuck with it instead of giving up.

and I'm glad you posted the update, it might help someone else later.

jephthah 1,888 Posting Maven

i hv tried it but i couldnt open it

you cant access IEEE and computer science journals without a subscription.

i have a subscription to IEEE, but i wont post the articles because that would violate the terms of my membership, as well as this site.

why do you want someone else's "source code" anyhow? what do you think you're going to accomplish?


.

jephthah 1,888 Posting Maven

the entire thing is a ternary (three-part) operator that evaluates to some value, and you typically use it as a conditional assignment.

(condition) ? value if true : value if false

putting the condition in parentheses is not required, but it may help you to visualize it better. For example, instead of writing a conditional statement like this:

if (myVariable == TRUE)
    newValue = 0;
else
    newValue = -1;

you can write it simply: newValue = (myVariable == TRUE) ? 0 : -1; then you can do whatever you want with the newValue. if all you care to do is return it directly, just put the whole expression as the return value, like any other expression: return (myVariable == TRUE) ? 0 : -1; .

jephthah 1,888 Posting Maven

CHAMPNIM

check out this example:

http://www.captain.at/howto-simple-serial-port-test-example.php

and just to clarify, your C code is not dependent on CodeBlocks ... CodeBlocks is just the development environment (IDE) ... your C code is dependent upon being compatible with the "GCC compiler" ... this is standard ANSI C, and will serve you well to learn to do the majority of your coding on.

MSVC is another widely-used compiler. you could, at some point, download the free MSVC compiler and use it from CodeBlocks... but worry about that later.


.

jephthah 1,888 Posting Maven

best shmest.

I'm not trying to give bulletproof homework solutions.

i was just pointing out how one could "count characters" just as easily as one could divide/modulo


.

jephthah 1,888 Posting Maven

LOL, come on, dude. just look at this

Which header files hv to be included to access serial ports using the codebloscks compiler? is dere a tutorial fr d same????

hv?
dere?
fr?
d?

are you serious???

you sound like a complete tard. if you cant be bothered to "talk" correctly, what matter is it to us whether or not you ever get your code right?

you know, i cant speak for anyone else here, but this... hardware, C code ... it's my industry. it's how i make a living. i spend 45 hours a week at a job, and i have to deal with many co-workers, from different areas. and the simple fact is, i don't want to work with idiots.

i just don't. Life is too short, and i don't have the patience for them. So it's in my interest to dissuade people who i think are idiots from entering my industry. While I can't actively *stop* them, I certainly don't have to *help* them.


.

jephthah 1,888 Posting Maven

You will write the C++ program

notice this line right here, the first line of your assignment. now, lets meditate on it for a moment... what do you imagine this means?

I have worked on this programming for a while ,
but always have problems here and there ,~

yeah, really? here and there? ... you know, i don't think i believe you.

.

jephthah 1,888 Posting Maven

or....

int getNumDecimalDigits(int value)
{
    char myString[16];
    sprintf(myString,"%d",value);
    return strlen(myString);
}

:P


.

jephthah 1,888 Posting Maven

well, if (a=b) { . . . } is perfectly valid, as im sure youre aware.

i used to purposely code in that manner, before i got the habit slapped out of me by a principal engineer who (god forbid!) insisted code be readable. :P i mean, not in such a trivial way, but more like the convention: if (err = myFunction()) { . . . } it's not uncommon. i'm not saying it's good style, but i see people code like that a lot.


.

jephthah 1,888 Posting Maven

pseudo-code:

for (element = 1 to 100)
    array[element] = random()
jephthah 1,888 Posting Maven

im just making a semi-informed guess.

the lines are definitely blurred between "gaming" video cards and 3D graphic workstation cards these days, and the info im drawing from (recollection, mostly) is a couple years old

also, openGL may well work on some cards, even though the card is not officially "certified" for open GL...

its a common issue. its almost random as to which video card/OS combo will work, and which ones won't. most of the times, the ones that "don't work" will work partially, but with some negative effects (choppiness, etc.)


.

jephthah 1,888 Posting Maven

OpenGL has strict video card requirements. it's a longer process to get drivers certified for "OpenGL", and thus video cards that have been fully qualified are more expensive than normal "gaming" video cards.

You typically will find such cards in engineering workstations, not so much in average "gaming" computers, and probably pretty rarely in run of the mill workstations.

jephthah 1,888 Posting Maven

um, send a wireless command to a robot who is standing by a switch?

ithelp commented: Great idea. +4
jephthah 1,888 Posting Maven

so, you're just taking an EXE, all by itself, and trying to run it on the new computer?

if so, maybe you should try compiling from source on the new computer and see how it works.

i think youre going to need to build a distribution kit if you want to, well, distribute it.

jephthah 1,888 Posting Maven

If you do need to port someday, it is trivial to implement it in terms of the new platform.

yeah, on second thought, I guess porting _kbhit() from MSVC/Win32 to a GCC/POSIX solution is not terribly difficult.

So... Dragon's suggestion for using _kbhit() is entirely appropriate.

.

jephthah 1,888 Posting Maven

Thank the gods you finally arrived to give us the answer to this perplexing problem.

and to think we were just getting ready to close this one out as "unsolved"

*whew*

(next time, please dont wait so long, mmmkay?)

jephthah 1,888 Posting Maven

its so hard to guide you on how to best prepare becasue we dont know what the focus of material was, and we dont know which aspects the professor deems to be more/less important.

make sure you understand the whys and wherefores of all the problems in previous assignments.

Generally speaking, i would definitely hit up the TA's or whatever the assistants/graders are called at your school. if theres any sort of "practice exam" available, DO THAT. check the library if there are some sort of "course reserves" and the course online repository for old exams. finding a study group to join, if not too late .... Sorry if these are generic suggestions, but honestly, it's how i got through engineering school.

the things that Alex posted above are good general problems, but may not be the best use of your preparation time. Unfortunately, there's just no way for any of us here to tell.

good luck.

.

jephthah 1,888 Posting Maven

use those libraries (conio.h, windows.h, etc.) at you're own peril. they offer quick solutions, but are completely non-portable. you'd do much better for yourself learning to write a multi-threaded solution.

jephthah 1,888 Posting Maven

if you're saying that Vista kind of sucks, i might agree, but it has nothing to do with C, or vice versa. I do C development in vista just fine.

the question is, what IDE/Compiler are you using, to program C?

jephthah 1,888 Posting Maven

i didnt really get what u r saying ... i need a prog to find the num of solution ... waitin 4 a reply as soon as possible...... thx..

do u wnt da goog srch n stuf or r u wnt 4 me 2 jus prog da c code n post it str8 up 4 u 2 b chiln stuf ... kkthx c u l8r d00d lolz.


.

Aia commented: What kind of random generator did you use? +8
jephthah 1,888 Posting Maven

your instructor is smoking crack. learning to code on Turbo C will only hinder you, by teaching you non-standard C that will not ever work on any compiler used by the real world. you'll have to UNLEARN half the stuff you learn. Oh well, I'm going to drop the issue.

your program, considering your skills, i think is too ambitious to try and tackle all at once. make a smaller program to do simple tasks, and don't even think about graphics.

repeating what i said earlier, i think the following requirements would be a good start, and give you some simple functionality that you could build more complex functions into later:

(1) print some text to the screen that the person should type.
(2) start a timer, and begin collecting typed input from user.
(3) once the user indicates they have stopped typing, stop the timer
(4) calculate total (elapsed) time, and the number of errors in their typed text compared to the original text.
(5) print test results, allow them to try again or exit

technically this is more of a "typing test" than a "tutor", but all of the functions that you will have to code for this example, are functions that will be needed by a more complex typing tutor, so you won't be wasting your time.

it would be a good place to start, and would give you something tangible to show when completed.


jephthah 1,888 Posting Maven

^ what he said.

the version you want is the one that has "MinGW" in the name. that's the GCC compiler.

i think you'll like the IDE, too.

jephthah 1,888 Posting Maven

hey, Vijay, please become familiar with the rules of the forums... you know, the ones that are posted as "ANNOUNCEMENTS" and stuck to the top of every forum here.

(1) http://www.daniweb.com/forums/announcement118-2.html

and

(2) http://www.daniweb.com/forums/announcement118-3.html


.

jephthah 1,888 Posting Maven

And what is "the desired" effect?

apparently he desires a function to convert seconds to milliseconds

now where is that function?

i know i left it around here somewhere....