andor 25 Posting Whiz in Training

use int main instead of void main.

andor 25 Posting Whiz in Training

Leave it to the WoLfMaN to figure it out. :cheesy:
@Andor: Surely you are using hybrid mode in IE, and linear mode in Firefox.

Just so that to make it clearer, I attached an image so that you know how to change it (if you didn't already know)

I don't think Dani was speaking English in this particular instance. :mrgreen:

Yes you are right when I switch to linear mode it's OK. Sorry but I didn't knew that. Mystery solved.

andor 25 Posting Whiz in Training

I dont understand (I'm not english speaker). Even I refresh the page the error is the same (for firefox). I need to go now C U tomorow.

andor 25 Posting Whiz in Training

I think that there is a bug when watching some posts with firefox. The post orders are different for internet explorer. You can see it is the same address but there is a difference between the third post. See the pictures and you will understand.
PS: Dowload the pictures to see them more clearly

andor 25 Posting Whiz in Training

It was just added yesterday, to do where language is anything within our code snippet library.[/QUOTE] Ok while U're here just to report that the posts order are different for internet explorer and for firefox. EDIT: is that a bug?[code=language] where language is anything within our code snippet library.

Ok while U're here just to report that the posts order are different for internet explorer and for firefox.
EDIT: is that a bug?

andor 25 Posting Whiz in Training

I haven't included the main func on this forum as I find compilers are finicky creatures - some prefer main(0) or void main() whilst others prefer void(0) - the variations are seemingly endless!

I've declared the ages as integers as they are whole numbers.

WHAT!?!? Okay use this

int main()
{
   /* your code going here */
   return 0;
}
andor 25 Posting Whiz in Training

Actually, you can now use [code=c] :) Tags added for him.

Ah nice didn't know that it exist.

andor 25 Posting Whiz in Training

Um you need a main func. Where did you declared the age variable?

do
{
   /* stuff */
} while(/*your code going here */);

This is a do while loop, not

do
{
  /* stuff */
}
if (/* something*/)
{
}
/* and then */
while();
andor 25 Posting Whiz in Training

Did you copile this? Use [ CODE] [ /CODE] tags.

andor 25 Posting Whiz in Training

Also you can do it with string.

len = sprintf(buff, "%d", num);
   
   for (i=0; i<len; i++)
   {
      printf("%d\n", buff[i] - '0');
   }

Where num is in your case 1567.

andor 25 Posting Whiz in Training

When I post something to this thread its not there. Whats happening here.
FOR tiriamwe: Ok fix the code becouse it wont compile. Read this. Posting errors of your prog

test16.cpp: In function `void AddWords(char*)':
test16.cpp:54: parse error before `else'
test16.cpp:60: break statement not within loop or switch
test16.cpp: At global scope:
test16.cpp:62: parse error before `}' token

EDIT: Its ok now but there is some kind a bug when posting, becouse if I reply to 6th post of this thread my post is missing.

andor 25 Posting Whiz in Training

here is the whole program:
line in bold when debugged is giving the value of currunt->words as Could not watch this variable

Wont compile. Fix the errors and read this

andor 25 Posting Whiz in Training

Declaring f as global but that is bad practice. I don't know what you want to do. You are not calling fn func at all.

andor 25 Posting Whiz in Training

Read this

andor 25 Posting Whiz in Training

I asume that temp is typo error becouse its text not temp. Is check->words valid? When you debuging what are the values for check->words and for text.

andor 25 Posting Whiz in Training

Its not a big deal, everyone mistakes and we learn from it.

andor 25 Posting Whiz in Training

Hi there, im a c++ noobie. I have a class called node. Node has a data member id. When i try and access id in the obect named f outside of main visual studio 2003 gives me the errors:

: error C2065: 'f' : undeclared identifier
error C2228: left of '.id' must have class/struct/union type
type is ''unknown-type''

thanks in advance

You declared f in main function and not in fn function thats the problem. Declare f in fn function.

andor 25 Posting Whiz in Training

This is valid if (strcmp(check->words,text)==0) and this is not if (strcmp(check->words,text[30])==0)

andor 25 Posting Whiz in Training

i've tried strcpy() but when i compile and run it the prog hangs then crashes. i'm probably doing something basically wrong in the fubction maybe.

int main(int argc, char *argv[]){
    
    char filename[30];
    strcpy(filename, argv[1]);
    
}

Yes probably U R doing something wrong. What R U passing as arg[1]? Probably nothing and thats why it crashes.

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

int main(int argc, char *argv[]){
    
   char filename[30];
   if (argc != 2)
   {
      printf("Dude are you passing something at all");
      return 1;   
   }
   strcpy(filename, argv[1]);
   printf("filename: %s\n", filename);
   return 0;
}

This works for me.
PS: memcpy is safer

andor 25 Posting Whiz in Training

Try memcpy or strcpy.

2.14.4 memcpy

Declaration:

void *memcpy(void *str1, const void *str2, size_t n);

Copies n characters from str2 to str1. If str1 and str2 overlap the behavior is undefined.

Returns the argument str1.

2.14.13 strcpy

Declaration:

char *strcpy(char *str1, const char *str2);

Copies the string pointed to by str2 to str1. Copies up to and including the null character of str2. If str1 and str2 overlap the behavior is undefined.

Returns the argument str1.

andor 25 Posting Whiz in Training

Did you searched the google?

andor 25 Posting Whiz in Training

To many errors you have. Remove ; after void gettradeIn( float& tradeIn) . Where void getdownPayment(float& downPayment) func ends?

andor 25 Posting Whiz in Training

that won't work either. strcmp() expects a null-terminated string. Just passing the address of word does not make it null-terminated.

I agree, my mistake. I didn't think just saw that strcmp accepts pointer to char. But how did he pass the whole string inside one char?!?
Ah I know the answer, he didn't.

andor 25 Posting Whiz in Training

word is a single char and strcmp takes char *. So you need to pas strcmp(p->words,&word) as second parameter. Are you shore: int getCount(char word) is right. Becouse there are more sense if it was int getCount(char * word)

andor 25 Posting Whiz in Training

What kind of error? You want to print the file to the screen or back to file?

andor 25 Posting Whiz in Training

post your code

andor 25 Posting Whiz in Training

Declare the both globals as locals inside the main func.

int transfer_sequence (char * initial_sequence, char * fix_sequence);
int check_gene (char * fix_sequence);
int main()
{
   char initial_sequence[513] = {'\0'};
   char fix_sequence[513] = {'\0'};
   /* stuff */
   unacceptable_char = transfer_sequence(initial_sequence,    fix_sequence); /*check for bad chars*/

   gene_found = check_gene(fix_sequence); /* check for gene */
   /* rest of stuff */
   return 0;
}
andor 25 Posting Whiz in Training

Thank you again, I got that part to work, however I am having trouble storing the name. It worked fine with two %s's for storing but I can not seem to get it to print the name (Kyle Davidson) for example. It gives me an error.

Did you try something like this?

char * ch = NULL;
	
	printf( "Enter the first name: ");
	fgets(fName, sizeof(fName), stdin);
	if ((ch = strchr(fName, '\n')) != NULL)
	   *ch = '\0';
	printf( "Enter the last name: ");
	fgets(lName, sizeof(lName), stdin);
	if ((ch = strchr(lName, '\n')) != NULL)
	   *ch = '\0';
	printf("%s %s\n", fName, lName);
andor 25 Posting Whiz in Training

I allready said that you read the link. Instead of scanf use fgets. This is your code.

/* This program asks the user for a few numbers and computes their average */

#include <stdio.h>
#include <string.h>
#define NumNumbers 5



int main( int argc, char** argv )
{
	int	i;
	int	g;
	float	number;
	float	average;
	char	fName[255];
	char	lName[255];
	
	
	
	printf( "Enter the name: ");
	scanf( " %s %s", fName, lName);
	
	printf( "Enter the number of grades to average: ");
	scanf( " %d", &g );
	
	printf( "Enter %d grades (must be one of A, B, C, D, F)...\n", g );
	average = 0.0;
	for( i = 0; i <= g-1 ; i++ )
	{
		do
		{
			printf( "  Grade %d: ", i+1 );
			/* getchar(); */
			scanf( " %f", &number );
			
			if( (number < 0.0) || (number > 10.0) )
				printf( "   Invalid grade (%g)\n", number );
		}
		while( (number < 0.0) || (number > 10.0) );
		
		average += number;
	}
	average /= g;

	/* Print the results */
	printf( "has a GPA of %.2f\n", average);
	
	return( 0 );
}

For temp solution uncomment the getchar, but you must use fgets instead of scanf. After that you dont need the getchar kludge.

andor 25 Posting Whiz in Training

hi,
i need the program code and algorithm to find the sum of the sin and cos series, print 1/232/34543/4567654 in the form of a triangle. Please mail me the solution on ****
thanks so much.

I have a feeling that your e-mail address will be removed. Read the forum rules.

andor 25 Posting Whiz in Training

If you using scanf than:
input: G (hit enter) X (hit enter) your output GX
If using getchar
input: GX your output GX.

#include <stdio.h>

int main()
{
   int sequencetemp;
   char sequence[512];
   unsigned short x;
   
   for ( x = 0; x < 511; ) { /* x < 511 space for '\0' */
   
      sequencetemp = getchar();

      if ((sequencetemp=='A') || (sequencetemp=='T') || (sequencetemp=='G') || (sequencetemp=='C')){
         sequence[x++] = sequencetemp;
      } 
      else if (sequencetemp=='X'){
         sequence[x++] = sequencetemp;
         sequence[x] = '\0';
         break;
      }
      else {
         printf("ERROR\n");
         return 1;
      }
   }
   puts("The string is: ");
   puts(sequence);
    
   return 0;
}
andor 25 Posting Whiz in Training

Check this link

andor 25 Posting Whiz in Training

What part U dont understand? The void pointer? Well void pointer can be used if you are not shore which type will be passed to func compare.
BTW const void must be separated.

andor 25 Posting Whiz in Training

hmm... fgets seems useful, but how would I modify the method in the second "this" to read a sequence of up to 512 characters, adding only G,A,T, and C to the array, and stopping the input before the X at the end?

Could this be done in a loop?

sorry I didn't read your post carefully. I asume that U must use scanf, so then U must. Ok the problem is your loop. Dont increment x every time.
Check this

for ( x = 0; x < 511; ) { /* x < 511 space for '\0' */                                           
                                                                                                 
   scanf("%c", &sequencetemp); /* dont like this part but if teacher said than ... */            
                                                                                                 
   if ((sequencetemp=='A') || (sequencetemp=='T') || (sequencetemp=='G') || (sequencetemp=='C')){
      sequence[x++] = sequencetemp;                                                              
   }                                                                                             
   else if (sequencetemp=='X'){                                                                  
      sequence[x++] = sequencetemp;                                                              
      sequence[x] = '\0';                                                                        
      break;                                                                                     
   }                                                                                             
   else {                                                                                        
      printf("ERROR\n");                                                                         
      return 1;                                                                                  
   }                                                                                             
}
andor 25 Posting Whiz in Training

For me there are much more errors. Are you shore that you posted the whole code?

andor 25 Posting Whiz in Training

For obtaining single char you can use getchar which returns int. You can read this and this for obtaining the whole string.

andor 25 Posting Whiz in Training

Your type A, can it be outside of the main function? Still your pst struct is local beside that.
NOTE: Instead of void main use int main.

void function1(void *pStr)
{
   A * ptmp = (A *) pStr;
   
   ptmp->a = 0;
   ptmp->b = 0;
   ptmp->c = 0;
   ptmp->ch = '\0';
}

if type A is in front of int main.

andor 25 Posting Whiz in Training

I'm having touble trying to send arrays from funciton to function. The thing I can't do is make a global variable (one of the rules set by the teacher). I don't know what I'm doing really, so let me know if it's even doable.

The answer is yes as specified above. Just if the array is big and you want to save stack then you can pass the address of the first element of array.

foo(int * array)
{
   /* some action with array[] */
}

int main()
{
   int array[MAX];  /* MAX must be defined */
   foo(array); /* or foo(&array[0]) */
   return 0;
}
andor 25 Posting Whiz in Training

hi jack here,i want to which are the best websites who could offer me clear and total info and tutorials on c++ and c programming..

Look at the firs thread in this forum. For example this (for C)

andor 25 Posting Whiz in Training

okie thanks but how can i round it off to one deciamal place?

for example

(PartialComponent/TotalComponent)*100
90/235=38.3 %

38.3 should be the return value

anyone? i shouldnt be using any math.h function etc.

Your func CalculatePercentage should return double or float instead of unsigned int, and to round read this

andor 25 Posting Whiz in Training

This is not enoughf information. Post your code.

andor 25 Posting Whiz in Training

Write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of services: regular and premium. Its rates vary depending on the type of service. The rates are as follows:
Regular service: $10.00 plus first 50 minutes are free. Charges for over 50 minutes are $.20 pre minutes.
Premium service: $25.00 plus:

  1. for calls made from 6:00am to 6:00pm, the first 75 minutes are free; charges for over 75 minutes are $.10 per minutes

for calls made from 6:00pm to 6:00am, the first 100 minutes are free; charges for over 100 minutes are $0.05 per

Sorry but what is the question?

andor 25 Posting Whiz in Training

how will i round off the return value to decimal place with tis function?

unsigned int CalculatePercentage(int TotalComponent, int PartialComponent){
return int((PartialComponent/TotalComponent)100);
}

You must multiply with 100 (for multiplaying use * ).

andor 25 Posting Whiz in Training

can anyone help me with some c++ coding?

I want to create a piece of code that would allow me to type in any random 30 numbers and for them to come out in ascending order.

Any help would be greatly appreciated

Hazdude

Try it and then post it.
EDIT: for help try this link

andor 25 Posting Whiz in Training

I am starting to use GDB, It can take in only executable form programs as argument is it? Or there are other options. I need to use gdb on a non-exe program directly.Can I do it?

Read the manual, but I think it takes only the executable (*.out, offcourse you must build it with debug option).

andor 25 Posting Whiz in Training

link. EDIT: Your code can not be compiled, remove the errors.

andor 25 Posting Whiz in Training

Here's my Prog...i dunno how 2 convert it...pls check..
its a pyramid...

#

#include<stdio.h>
main()
{ int a, b, c, d=0;
   clrscr();
   printf("Enter a No:");
   scanf("%d",&c);
   for(a=1;a<=c;a++)
   { for(b=1;b<=c*2-1;b++)
    if (b<=c+d&&b>=c-d)
    printf("*");
    else 
    printf(" ");
    printf("\n");
    d++;
   }
   getch();
  }

is my program correct?
the output must be..a pyramid

Use int main. Its seams ok to me but I dont like non standard functions like clrscr() and getch.

andor 25 Posting Whiz in Training

how proceed c programming in unix just for practicing.

U can start here

andor 25 Posting Whiz in Training

i cant get this to work for an midi i have... can sumone code this to work for it? or possibly a while nnew code that works... heres the 1 i am using..

#include <iostream> 
#include <windows.h>   // for PlaySound() 
#define SND_FILENAME 0x20000 
#define SND_LOOP 8 
#define SND_ASYNC 1 
using namespace std; 
int main() 
{ 
  // play sound as loop (remove SND_LOOP for one time play) 
  // file boing.wav has be in the working directory 
  PlaySound("ff7vict.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC); 
   
  cin.get(); // wait 
  return 0; 
}

I asume that the qoute is your task. Did U noticed that U have to play wav file, and U say U want to play midi. Just for your information midi dont have samples inside the mid file. It contains midi messagess. The midi decoder generates PCM samples from tables (the largest table is wav table which consist raw PCM samples) according to these midi messages. Thats why midi files are much much smaler than mp3, wma files and offcourse wav files. So dude forgett the midi files becouse than U need to implement a midi decoder which is not your task.

andor 25 Posting Whiz in Training

Hello guys,

I am taking the MIPS assembly course this semester. indeed, I am struggling with this course. any way i need ur help ..

My guestion is how to make the output appears right justified and how to connect the previous functions to the new function which is the right justification one.. plzzzz guys helpme out and clue me in..

I did the following code ... if it needs some corrections just tell how to correct and where ....

.data
buffer: .space 13
.text

li $t5, 12
li $t6, 10

add $a1, $a1, 12
sb $0, 0($a1)
move $a2, $a0
loop:

addiu $a1, $a1, -1

bnez $a0, loop

li $v0, 5
syscall

div $a0,$t6
mflo $a0
mfhi $t4
addi $t4, $t4, 48
sb $t4, 0($a0)
addiu $a1, $a1, -1
addiu $t5, $t5, -1

bnez $t5, loop2
loop2:

li $t2, 0x20
addiu $t5, $t5, -1
sb $t2, 0($a1)
addiu $a1, $a1, -1

li $v0, 8
la $a0, buffer
li $a1, 13
syscall

Dont understand your problem.

My guestion is how to make the output appears right justified and how to connect the previous functions to the new function which is the right >ustification one.. plzzzz guys helpme out and clue me in..

What this means? BTW you cant do this sb $t4, 0($a0). Specify your problem more clearly. Add main: after text section.
Use only temporary registers and not …