Adak 419 Nearly a Posting Virtuoso

I have bind.exe, as part of Visual Studio C/C++ 6.0. It is in the

C:\Program Files\Microsoft Visual Studio\Common\Tools
directory.

I looked at it with a hex editor, and neither I nor my AV program (scanned it twice), see any indications that it's a virus**. It says it binds an image to a dll file. I haven't used it, and for an answer to your question, I'd refer you to the MSDN library.

**doesn't mean it couldn't be malware of some kind

Adak 419 Nearly a Posting Virtuoso

I believe you can run Turbo C in Windows 7, but it has to run inside a virtual machine.

This is how it ran in WindowsXP as well, using the NT VDM. I haven't done this yet, but surely will some time soon. Google it, and also check out DOS BOX, Virtual Box, and VM for their solutions.

Adak 419 Nearly a Posting Virtuoso

You've copied code and said "it doesn't work". That's it. :(

Copying code is NOT programming, and you don't seem to be studying programming. You seem to be mastering the art of finding code, and copying it.

I'm not interested in fixing somebody's code that I don't know, from some other forum, so you can get through an assignment, without studying.

It's fine to study other people's code, but you need to study up, and write your own, also. Copy and pasting won't give you good answers, reliably.

Adak 419 Nearly a Posting Virtuoso

Every time the program makes a new guess at the answer, you should count one more comparison.

The number of if or else statements doesn't matter, unless a new guess is made, inside it.

In the binary loops I've seen, only one guess per iteration is made. Note that anyone could create a binary loop which made two guesses each iteration, but I have never seen that -- it's just a logical possibility.

Adak 419 Nearly a Posting Virtuoso

I'm confused.

Linked lists can be done as a queue (a regular list or line), or as a stack (like a stack of plates).

push and pop are used for stacks, and data is entered one at a time, at the top of the stack, only.

lists use a FIFO first in, first out, type of data flow, and the new data is simply added to the tail end of the line - again, one at a time.

I don't know which you're trying to make here, or why you have an option to make more than one node at a time, or why you have nested structs, etc.

Maybe you can tell us what the data struct is being used for, then we can understand it more.

Adak 419 Nearly a Posting Virtuoso

scanf() returns the number of items it has worked with - not EOF, etc.

fgets(nameOfSring, sizeof(nameOfString), stdin);

Always takes in a full line of code - of any type, with any punctuation, but you specifiy how many char's it should take in.

Puts the newline char: '\n', at the end of the string, then

Adds the end of string marker char: '\0', to every line of input it takes in.

The keyboard buffer has no "junk" char's left over in it.

Never overflows the string buffer - will leave off the newline and end of string marker char, in a pinch. (don't leave it "in a pinch", give it room to work).

Once the input is in the string buffer, you can work it any way you want to get your specific variables out of the string - ssccanf() is one way,

The biggest thing is you've got the input from the file or user, "in a cage", and you can now test it, remove parts of it as needed, convert certain char's, delete others, YOU CAN DO WHATEVER YOU WANT, through multiple tests, to get good input.

Try that with scanf() and you'll be practicing your cursing before long. ;)

If you indent your code with spaces, instead of tabs, the curly braces can line up much better. 2 to 4 spaces, is normally best. Your compiler (editor), will have an option for this.

Adak 419 Nearly a Posting Virtuoso
#include<stdio.h>


int main()
{
  int nr_products, nr_prices, price, over10=0;
  char product[40]={'\0'};

  printf("Enter the number of products");
  scanf("%d",&nr_products);
  getchar();

  printf("Product:");//enter the product
  fgets(product, sizeof(product), stdin);

  printf("Price:");//enter price
  scanf("%d",&price);
  getchar();
  for(i=0; i<nr_products;i++) 
  { 
    if(price>10)//condition over 10
    {
      printf("\nThis product has a price over 10: %s",product);//product over 10
      over10++;
    }	
  }
  if(over10==0) 
  { 
    printf("\nNo product cost over 10."); 
  }
  else {
    if(over10==1)
      ch='';
    else
      ch='s';
    printf("%d product%c cost over 10.", over10, ch);
  }
  return 0;
}

Not a complete solution to what you need perhaps, but a good start. I have not tested/debugged any of the above.

Adak 419 Nearly a Posting Virtuoso

After each scanf(), add a getchar() to pull the left-behind newline char, off the keyboard buffer.

Scanf() is fragile - it requires a clean input stream, and even then, it should be used for highly formatted input, only.

fgets() is far more robust and flexible. Please use [code] tags around your program code!

Adak 419 Nearly a Posting Virtuoso

The program uses nr_products and nr_prices, without having given them values! :(
These variables were declared BUT NOT initialized to any value.

if statements need TWO == in them, instead of just one =.

You need a for loop (best) to control how many times a price needs to be entered.

products should be a string, instead of just one char.

Lots of work to do on this program.

Adak 419 Nearly a Posting Virtuoso

A binary search just takes a guess on the answer, and if the guess is too high, it cuts down the top of the search to one element's value below the guess. If the guess is too low, it brings up the bottom value of the search, to one element's value, above your guess.

So every time you guess and miss, you cut the search space into an ever smaller search space. Indeed, on each guess it makes, since it guesses the middle number (and unless that guess is correct), the search space is cut in half! ;)

In order to work, the values being searched, must be sorted. Since your numbers aren't sorted yet, that would be the necessary first step.

Instead of posting your assignment, post your assignment AND your attempt to solve it, AND what has you stumped, next time.

And Welcome to the Forum! ;)

Adak 419 Nearly a Posting Virtuoso

The answer is that scanf() leaves the newline char (which is generated when you hit the enter key), behind.

To solve your problem, add a getchar() line of code, immediately below your scanf(), and all will be well, (unless you press other unnecessary keys).

Now you know just a bit of the problem of controlling user input, for your program. ASAP, stop using scanf() for programs that will be used for user input other than your own, and start using fgets() - it's much more robust.

Adak 419 Nearly a Posting Virtuoso

Go to the main C forum, and you'll see the grey tab of "Snippets", click on it.

Adak 419 Nearly a Posting Virtuoso

You need to highlight your code, then click on the [code] icon in the edit, which will post up two code tags for you.

Paste your code, between those code tags.

Otherwise, you code will be turned into html text and look really bad.

And yes, as noted above, you need to actually ask a question. ;)

Adak 419 Nearly a Posting Virtuoso

We just had a wonderful example of a binary search program in "Snippets" section of this forum, about two weeks ago.

Adak 419 Nearly a Posting Virtuoso

I don't like your algorithm, nor do I see anything "divide and conquer", about it.

Try this:

1) take in all the numbers of the array, then
2) use Quicksort to sort the array

Quicksort is a *brilliant* example of a divide and conquer algorithm.

Adak 419 Nearly a Posting Virtuoso

Most compiler's have a default return type of int - like Borland used to.

Today, you should be explicit about your return types, and they should be included in your function prototype.

What is the return good for?

Any answer to a computation the function is doing! Serious programming doesn't use much in the way of global scoped variables - they're local 99% of the time. A return is ONE way (a pointer to the variable being passed as a parameter to the function is another way), to bring the answer back to the calling function.

Adak 419 Nearly a Posting Virtuoso

OK, but you say you're using matlab to measure this, not C.

Do you have a C question?

If not, I'd Google up the answer to your other questions. You MIGHT find an answer here, but it's a real gamble, imo.

Good luck!

Adak 419 Nearly a Posting Virtuoso

Int return codes help answer the important question:

I ran the program, but did it finish normally, throw an error, or get caught in an endless loop of some sort?

By custom, a zero return indicates a successful program run. Other numbers might correspond to specific errors, and no return indicates the program is either still running, or has quit without returning a known error.

Adak 419 Nearly a Posting Virtuoso

Glad it worked out.

Adak 419 Nearly a Posting Virtuoso

Try changing "char" to "unsigned char".

BTW this code is almost letter for letter, right out of "The C Programming Language, by Kernighan and Ritchie, page 103. That's the "Bible" for C programming. Only difference is the return is int in the book.

(and ptr instead of p as the name of the pointer).

And WTF compiler are you using? I want to burn it at the stake!! ;)

Adak 419 Nearly a Posting Virtuoso

Sorry, make that "objective-C tutorial", instead of C#.

Adak 419 Nearly a Posting Virtuoso

I believe this is what your teacher wants:

size_t MyStrlen(const char *s1) {
  char *ptr = s1;
  
  while(*ptr != '\0')
    ptr++;
  
  return ptr - s1;
}

Which is the same thing your function was doing, but using only pointers.

I'm used to seeing the return from this, being an int, instead of a size_t, but no matter. If you have trouble getting the size_t to print out right, then just cast it to an int, in the printf() statement.

Adak 419 Nearly a Posting Virtuoso

You're welcome, guy.

When it refers to "that variable", it is not describing the "other variable". Teacher's description has jumped back to refer to the si variable.

So you're OK on that point.

What you're not OK on is the use of pointers++. Teacher doesn't want size_t input++ at all.

I'm going to post this, and read just a bit of code.

Adak 419 Nearly a Posting Virtuoso

IMO, the best thing to do is Google one of the many C# tutorials on the web, and go through them first.

THEN you'll be primed to start working through whatever problem you want to tackle.

When you have NO idea of where to start - don't start - get that idea first! ;)

Adak 419 Nearly a Posting Virtuoso

Logically, you don't need anything else - especially not another const char *.

Can you post the EXACT assignment - something has been misunderstood, I believe.

Adak 419 Nearly a Posting Virtuoso

To do what you are doing so far, you don't need to change anything except get the right identifier for your size_t to print out OK.

If you can't find it at all, then yes - cast it to an unsigned int and use %u

Adak 419 Nearly a Posting Virtuoso

In your compiler's help files, look up what the correct format identifier is, for size_t.

For me, it's an unsigned int. For you, it could be an unsigned long "%lu", or an unsigned short "%hu", or even have a unique identifier, all it's own.

There are a BUNCH of format identifiers for printf. Also, it has length modifiers, like the "h" in "%hu", that I mentioned just before.

Find that right identifier and length (if length is needed), and you'll be good to go. If you can't find it - Google it, and be sure to mention your compiler's name in your search on Google.

Edit:
P.S. s1 IS a const char *, because the s1 string is only measured - not changed. si is just ONE parameter (even though it has two words to describe it).

Adak 419 Nearly a Posting Virtuoso

To be consistent, I would:

1) remove the cast to int, in the printf() statements
2) change int input to size_t input, in the MyStrLen() function

and

3) use %u for the format identifier in the printf() statements.

That works for me, with no errors or warnings, and gives correct results.

Adak 419 Nearly a Posting Virtuoso

You were posting your updated code, at the same time I was writing my post - and looking at your first post, only. I was also looking into my header files on "size_t", which is why my post was so much later than yours (although the post was started before you finished).

Which not only confused you and I, but the forum software, as well (I wound up with a double post).

Did you try %u, and what is your compiler?

Adak 419 Nearly a Posting Virtuoso

<moderator, please delete>

Adak 419 Nearly a Posting Virtuoso

I have some idea's for fixing it, but that's NOT the code that you posted!

I can't fix code that I can't see -- trust me on this.;)

Post the code that you tried, and got this error on, and tell me what compiler you're using, and the answer shouldn't be too difficult.

(Basically, the error is quite right - %d is for int's. size_t will be an unsigned int, so try using %u).

Adak 419 Nearly a Posting Virtuoso

We would need two things to help you:

1) See your work starting this program

and

2) Post the details of the program you need to make.

"Receipt program" isn't nearly enough to know what you need the program to do.

And Welcome to the Forum! ;)

Adak 419 Nearly a Posting Virtuoso

What have you tried to solve this problem?

Adak 419 Nearly a Posting Virtuoso

Lots of problems with this code:

1) The logic is poor - an endless loop, then a break here, a break there, another break someplace else...

Is this logic for a program, or a Chinese fire drill? ;)

One break, maybe two, OK. Three? No. This is WAY too simple a loop for three breaks.

2) "%2d" is a good format specifier for printf(), but not for scanf(). Delete the 2 from it.

3) After each scanf() lines, add a getchar() to remove the newline char (caused by hitting the enter key), from the keyboard buffer.

That will stop your endless looping (along with #2).

Do while() loops work well for user input:

do {
  day = -1;
  printf("\n Enter Your Day's Number: ");
  scanf("%d", &day);
  getchar();
}while(day < 0);
Adak 419 Nearly a Posting Virtuoso

Welcome to the forum, Priva.t! ;)

A few very solid suggestions for you:

1) For your problems, unless it's EXACTLY the same, always start a new thread
2) You have to be VERY specific about what you are asking about. "Draw nonlinear objects", doesn't tell anyone what you are stumped on doing.

3) With your first post on a subject, post your efforts to solve the problem. This is a forum policy to reduce the "I need the codes for this!" kind of posts.

Adak 419 Nearly a Posting Virtuoso

In most cases, you don't want to shuffle data records around in a database.

If you have 3,000 students in a school, and a 3,200 student array of structs to handle their records, whenever a student leaves the school, you don't shuffle a bunch of records down to compact the database.

What you want to do is simply to mark out the student's fields (maybe a student ID number), and their name, to 0 and '\0', respectively. Now your program knows that new records can be put into those empty records.

Details include:
1) Your display and printouts of the records will not include records with zero'd out ID's or Names.

2) Your database will not always be kept in sorted order, but you don't care - you will have a small integer field in an auxiliary array, that your program will sort by, and use it to display or print any records, in sorted order.

That gives you the flexibility to display your records sorted by ID's, or Name fields, or any other fields (like age maybe), WITHOUT having to actually move your records around - at all. :)

The key idea is to minimize moving data around - that makes:
1) Your program more responsive - it doesn't waste time sorting and re-sorting the records.

2) Less wear and tear on the hard drives

3) Less power is used by the computer

4) Better data integrity, because …

Adak 419 Nearly a Posting Virtuoso

Change the code in lines 14 and 16, above. Replace the k index, with the j, as below:

if(adc_result[j]>max)
         {
            max=adc_result[j];
Adak 419 Nearly a Posting Virtuoso

I never give people the address to my house.

I always give them a copy of the address to my house.

They always find my house, with no problem. ;)

When you post code, use CODE tags around your code - always.

Adak 419 Nearly a Posting Virtuoso

Two things:

1) Your logic for max is reversed. Use > max, not < max.

min=adc_result[0];
      max=adc_result[0];
      for(j=0;j<i;j++)
      {
         if(adc_result[j]<min)
         {
            min=adc_result[j];
         }
      }
      for(k=0;k<i;k++)
      {
         if(adc_result[k]<max)   //change the < to >
         {
            max=adc_result[k];
         }
      }

and

2) You only need one for loop for this, you can do two tests in
one for loop, no problem.

ADCON0 = ADC_SINE;
      ADCON0bits.GO = 1;
      while (ADCON0bits.DONE);             //Terminates the A/D conversion when all the signal are converted
      adc_result = 256*ADRESH + ADRESL;      // Store the result

      min=adc_result[0];
      max=adc_result[0];
      for(j=0;j<i;j++)
      {
         if(adc_result[j]<min)
         {
            min=adc_result[j];
         }
         if(adc_result[k]>max)
         {
            max=adc_result[k];
         }
      }
      CurPosLCD(0x10);
      Out_LCD(ROM_TYPE "MIN= ");
      Out_Dec_LCD(min);
      CurPosLCD(0x20);
      Out_LCD(ROM_TYPE "MAX= ");
      Out_Dec_LCD(max);      
      Delay_sec(1);

The rest of your code pertains to the board you're working with. You'll have
to refer to it's reference material for any other errors it's giving you. Line #4 looks dodgy, but I'm not familiar with your board.

Adak 419 Nearly a Posting Virtuoso

Same basic logic. Just change the test in the top of the for loop - somehow, your testing condition has to know when it has reached the end of the numbers. You could have an ending sentinel value, or just use the number of integers that you have in the array.

Work with this, and post up your code if you're still stumped. You can do this.

Adak 419 Nearly a Posting Virtuoso

Let's look at a simpler example:

int i = 5;

switch(i > 2) {
  case 3: printf("\n i equals 3"); break;
  case 4: printf("\n i equals 4"); break;
  case 5: printf("\n i equals 5"); break;
  default: printf(\n i is greater than 5");
};

This code (in a normal program), will compile without warnings or errors in my compiler - BUT IT IS WRONG! Your compiler may warn you about this, or even throw an error.

if you can run it, you may get a wrong answer - in my case I get the "i is greater than 5" message - clearly the wrong answer.

Why?

The switch statement has the format: switch(expression), and that expression needs to resolve to an integral type. i > 2 may resolve to TRUE normally, but it does not resolve ANYTHING for the value of i,

So all the case (statements) can't find a suitable answer. Those statements must be of integral type, as well.

if you add: case 1: printf("\n i equals 1"); to the above switch statement, you see the problem immediately. i > 2 has indeed returned 1, and the switch statement will choose "case 1:", for it's choice.

If you have one of the latest C standard compilers however, please try the above, and post up what happens for you. The standard for C has changed a lot in recent years, and that may include the specifications for the switch statement - but I …

Adak 419 Nearly a Posting Virtuoso

Defines are just stupid "find and replace" substitutions, made before the program starts, and that can lead to a LOT of problems that are hard to de-bug.

A small function seems perfect for this.

Adak 419 Nearly a Posting Virtuoso

Vijay, you need to stop posting in an old thread - your post will be pretty much ignored and considered old as well.

Or posters will answer Psionics questions, and not yours. :(

Start a new thread, and be as specific as you can. Post the code that you're working with so we can see, as well as read, what you're doing, and what your trying to do.

Your new problem needs a new thread, and more information too.

Adak 419 Nearly a Posting Virtuoso

I doubt that you'll get what you want just by asking. We help people who want or need to program in C, and are able and willing to work.

If you want help, you'll need to get cracking, and post some work up. Ask specific questions about whatever has you stumped.

If you know your circuit equations (and I'm sure you do), this is not such a big problem. Your program can solve it like you would with paper and pencil, basically.

Adak 419 Nearly a Posting Virtuoso

Your for loop has a bad test to end the loop. x will always be greater or equal to zero, so the loop quickly is working outside the array.

for(x=0;x<strlen(title);x++)

should work.

It is more efficient to first, before the for loop, get the length of the string assigned to an int variable, then just use:

len=strlen(title);
for(x=0;x<len;x++) 
  //rest of code here

because that saves the program from having to measure the length of the string, every time through the loop.

Try to not use <31 or any other inflexible numbers in your code, if possible. Make it so it works with a char array of any length, see?

Adak 419 Nearly a Posting Virtuoso

In the second program, you have this bit of code:

char *a,*b;
FILE *fp,*fp1;

fp=fopen("int.txt","r");
fp1=fopen("obj.txt","w");
getsym_op();

while(1)
{
fscanf(fp,"%s",a);

Looks to me like you're assigning a string to a, but a is a pointer (not an array as you've used before with the same name), and a has been given no valid address yet.

I would NEVER have a char array and a char pointer, in the same program, using the same name - for heaven's sake. :(

Also, you use feof(), which doesn't work as you'd expect. Better to use the return you get from fscanf() to know when to break. Better yet, if you're just getting one string per row, use fgets():

while((fgets(buffer, sizeof(buffer), filePointer)) != NULL) {

}
Adak 419 Nearly a Posting Virtuoso

Congrats, Devel! ;)

Adak 419 Nearly a Posting Virtuoso

The outside sources may have become scarce, but you can always try and work it out, yourself.

The language is not the problem, but the logic you will need, to do this -- that's what you need.

Do you know how to transform this data from one type to the other, yourself - without a computer?

If so, start writing down the steps you would take, as specifically as possible.

With that, and a few examples of typical input and output, you can come up with the skeleton of the program.

Now you've reduced the problem from a "holy shit" to a manageable C problem, and we will then be able to help with what has you stumped.

Get that first part, done up. If you are able to google up some code for idea's, OK. If not, you'll still have a way to finish the assignment or project. And you'll have learned a lot in the process.

So will I. ;)

Wiki has some info on this:
http://en.wikipedia.org/wiki/Deterministic_finite-state_machine

Adak 419 Nearly a Posting Virtuoso

fgets() is a very good standard C way, to get a line of char's. You need a char buffer, where fgets() will put the chars, and you need some little bit of code:

char buffer[100];  //make it bigger than any line should be
fgets(buffer, sizeof(buffer), stdin);

sizeof() just tells fgets() it can get UP TO 100 char's and no more, from the file stream named stdin. In practice, it should get no more than 98 char's from the user, because it will need two spaces: one for the newline when the user hits the enter key, and one for the end of string marker char: '\0' (which is a zero in value).

stdin is a file that C opens every time it runs a program - along with stdout. stdin is the keyboard, and stdout is your monitor.

Adak 419 Nearly a Posting Virtuoso

What have you considered or tried? Post up what you have done, and we'll help answer any questions we can.