D33wakar 36 Posting Whiz in Training
#define EOF (-1)

You don't need to redefine EOF(already #defined in "stdio.h").

file = scanf("%d", &number);

You need to put this line in a loop to take consecutive inputs.

while((file = scanf("%d", &number)) == 1 && file!=EOF){
    sum += number;
    sum_squares += number * number;
    ++n;
}//repalces line 8 to 17

input:

sdev < input.dat 
where input.dat contains
1
2
3
4

output:

The average is 2.500000
The standard deviation is 1.118034
D33wakar 36 Posting Whiz in Training

The only problem I'm seeing right now is the way you're passing filepath argument to fopen

file=fopen("E:\PROFILES.DAT","rb+");

It should be like this:

file=fopen("E:\\PROFILES.DAT","rb+");
D33wakar 36 Posting Whiz in Training
if  (!sizeof(stdin))  while (getchar() != '\n');

stdin is just a pointer to a struct _iobuf, so the sizeof(stdin) will always return the size of a pointer variable(4 bytes). So your flushing mechanism

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

won't even execute.

- but this code 'll stop program when the input was empty primordially.

yes, so just press the "enter" key if you want to get rid of the "stopping moment".But then after we'll come to the same question Narue asked-

There's no portable way to do this without actually blocking for input and why do you think you need that behavior?

D33wakar 36 Posting Whiz in Training
int ok = 0;
for (x=0;x<=2;x++)
 {
 y=0;
 y++;
  if(c[x][y] ==d[x][y])
  ok = 1;
}

It only compares
c[0][1] with d[0][1]
c[1][1] with d[1][1]
c[2][1] with d[2,1] and so on.
If You want to compare each of the elements then, put it in a nested loop

for(x=0;x<2;x++)
    for(y=0;y<2;y++)
        if(c[x][y]==d[x][y])
        //rest of the code...
D33wakar 36 Posting Whiz in Training
int a,b;
a = b;//bad practice
char c[2][2];
char d[3][3];
c = d;

Well?Why don't you try that in your compiler? the answer is no. you cannot do that with arrays.

// or can you compare two arrays to get a true or false statement?
if ( c == d)

Though the compiler doesn't report any error in this case, you'll not get the intended result from it.Because here, the addresses of arrays c and d are being compared for equality which is never true.

// or if I want to know if two signs in an array are equal:
if ( c[1][2] == d[1][2])

This is the correct form.

Is it possible to use the equal sign = on arrays like you can use it on variables. If yes how do I write it correctly?

Suppose you have an array

int array[5]

then you can assign values to them like this

array[0]=1;//1st address assigned to 1
int i;//will be used as offset address
for(i=1;i<5;i++)
    array[i]=i+1;//2nd address contains 2, 3rd address contains 3 etc.
D33wakar 36 Posting Whiz in Training
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
#include <iostream>

only need this one

#include <stdio.h>
if( sprintf (fileparam, "fall%d.dat", i) == true )

sprintf returns number of characters written(int) in the array 'fileparam' or a negative number if an error occurred not a Boolean.

Your code when tidied up, looks like this:

#include <stdio.h>
int main(void) {
    FILE *file=NULL;
    int i;
    char fileparam[16];
    for(i =1; i<=10;i++){
        if( sprintf (fileparam, "fall%d.dat", i)>0){// returns positive if success
            if((file = fopen(fileparam,"w"))==NULL)
                printf("Error while opening file %s\n",fileparam);
            else {
                printf("%s was opened successfully.\n", fileparam);
                fclose(file);//close only if the file was opened
            }//done else
        
        }//done if
    }// done for

// the rest of process related to the file are trim


return 0;

 }
D33wakar 36 Posting Whiz in Training

You're opening the same file(handle) for reading and writing.

file = fopen (file2name, "r" );

it should be

write=fopen(file2name,"w")//"w" creates the file 'copy.txt' if it doesn't exist already
D33wakar 36 Posting Whiz in Training

Though, the thread has been marked solved, I would like to point few things out.

If you don't want to mess with getting rid of the '\n', then just use gets.

No, never use 'gets()' while taking strings as input(see why).People say don't use 'scanf' because it shows similar behavior to that of 'gets'.'fgets' is much more safer, and you should remove the trailing '\n' character as 'Ancient Dragon' suggested.
And this one is for 'hkdani'.

hkdani commented: Leaves helpful comments giving insights into the intracies of important principles in the programming language. +5
D33wakar 36 Posting Whiz in Training

In addition,
You can remove this line

#include <conio.h> //non- standard library,also not portable

'main' should always return int, like this:

int main(void)

and return statement at the end.

return 0;

add

fflush(stdout);

after the printf statements,by doing that you'll force the output to be displayed on the screen even if the output buffer is not full.
And finally don't use 'scanf' while taking string inputs,use 'fgets' instead:

fgets(name[i],sizeof(name[i]),stdin);
D33wakar 36 Posting Whiz in Training

Ola!

I'm still kind of new with the whole assembly language and just need some help with this program i'm writing.

What I want it to do is to ask a question -like for a number and then store that inserted number in a variable. And then test whether its bigger than 14 which I declared as a variable already as shown below-and then there is a loop to ask again what is the number. So I want the loop to run as many time the number the user entered.

output db 10,13, "Enter your number: $"
asq dw 10,13, "$" ; ascii values for a new line
stilltoimplement db 10,13, "Do calculations later on $"

.code 
    
jmp start 

    number db ?
    max db 14 ;max number
    
start:
    mov ax,@data 
    mov ds,ax
    
    mov ah,09 ;prints new line
    mov dx, offset output
    int 21h
    
    mov ah, 01 ;checks for key
    int 21h
    mov number, al
    
    cmp max,number
    jg start
    jl part2

part2:

    mov ah,09
    mov dx,offset stilltoimplement
    int 21h
    
ending:
    mov ah,4ch
    mov al,00
    int 21h ;End the program
    
END

It gives me an error in where I try to compare the two variables and says Illegal memory reference. Prob just something small

Any help will be appreciated!

Thanks

In line 24..
You can not use cmp with both operands being a memory variable. Instead use an immediate value

cmp number,14d  ;the immediate value must be the second operand

or you can also do

cmp al,max
D33wakar 36 Posting Whiz in Training

...that's your homework

I'm sorry that I sounded like your professor up there, but my only intention was to help you find the bug, and it was simple so I thought that you were able to find that on your own.

I'm thinking that your solution was the following for line 9.

printf("%d", matrices[Index][i])

No, it was not.
It was this:

printf("%d",matrices[i]);

Because, the pointer "matrices" you're passing to the function "Display" is equivalent to "matrices[index]" for which you dynamically allocated memory in your 'main'

matrices [Index] = (int *) malloc( size * sizeof(int));

And you only got the first member because 'Index' in your 'Display' function always remains zero.
So you can also do like this:

for (Index = 0; Index <= size; Index++)
{
    printf("%d", matrices[Index]);
}

And also I can't believe that someone who has done several projects is still having trouble understanding the concepts of pointers and then applying them?

D33wakar 36 Posting Whiz in Training

I don't understand - why compiler allows such code =

You can do like this then.

#if defined(_WIN32)||defined(_WIN64)

//Windows specific includes and code goes here..

#elif defined(linux)

//linux specific includes and code goes here..

#endif
D33wakar 36 Posting Whiz in Training

I now am having a problem entering values into the dynamic memory.

It's not a good idea to ask for favors for every single problem you face. You should learn how to debug your own code at least.

Line 17-20 is a for loop to increment the variable 'i' so a series of different values will be stored in the dynamic memory. However, it only reads in the first value and ignores the rest.

The problem is in your 'Display' function (in line 9 of your second code-see carefully) and that's your homework.

D33wakar 36 Posting Whiz in Training

That means he is using a different compiler than you are. Just ignore it.Pelles C has no such option.

Yes, it does.
Actually if "Enable Microsoft Extensions" option is unchecked, then compiler will issue the message:

If you are compiling a Windows program, make sure you use the /Ze option!

So '-Ze' is a command line option for the compiler which means 'Enable Microsoft Extensions'. Anyways, I'm glad that the issue has been resolved.

but the winmain() is the entry point for windows program.....
why compiler doesn't compiler such code =

This example code may help you, it compiles as a 'win32' EXE.

#include <windows.h>

void NewLine(void);
void ScrollScreenBuffer(HANDLE, INT);

HANDLE hStdout, hStdin;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;

int WINAPI WinMain(HINSTANCE hInst,  HINSTANCE qwe,LPSTR qwer, int ss){
    LPSTR msg="This is a win32 console";
    DWORD cWritten,cRead;
    char chBuffer[256];
    
    //Create console
    if(AllocConsole()==0){
        MessageBox(NULL, TEXT("AllocConsole"), TEXT("Console Error"),
                   MB_OK);
        return 1;
    }
    
    // Get handles to STDIN and STDOUT.
    hStdin = GetStdHandle(STD_INPUT_HANDLE);
    hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    if (hStdin == INVALID_HANDLE_VALUE ||hStdout == INVALID_HANDLE_VALUE){
        MessageBox(NULL, TEXT("GetStdHandle"), TEXT("Console Error"),
                   MB_OK);
        return 1;
    }

    // Write to STDOUT and read from STDIN by using the default
    while (1){
        if (! WriteFile(
            hStdout,               // output handle
            msg,                   // prompt string
            lstrlenA(msg),         // string length
            &cWritten,             // bytes written
            NULL) )                // not overlapped
        {
            MessageBox(NULL, TEXT("WriteFile"), TEXT("Console Error"),
                MB_OK);
            return 1;
        }

        if (! ReadFile(
            hStdin,    // input handle
            chBuffer,  // buffer to read into
            255,       // size of buffer
            &cRead,    // actual bytes read
            NULL) )    // …
vedro-compota commented: ++++++ +3
D33wakar 36 Posting Whiz in Training

If you want to run the above program, you should compile it as a console program. But when I compiled and ran your program,the winmain part didn't show up. I had to comment out the 'main' part to do so.

#include <stdio.h>
#if defined(_WIN32) || defined (_WIN64)
   #include <windows.h>
   #define WINDOWSS 1;
#endif
int mainmenu(void);
/*int main()
 {
	 char* mtext = " Please specify the number of the task. \n * You can choose on number from set = {1} \n * Specify \"0\" to exit\n" ;

   mainmenu();
  printf("\n%s",mtext );
  getchar();


 }*/
#if defined WINDOWSS

int WINAPI WinMain(HINSTANCE hInst,  HINSTANCE qwe,LPSTR qwer, int ss)
{

	 mainmenu();
char* mtext = " running WinMain version. \n" ;
  printf("\n%s",mtext );

 return TRUE;
 }
#endif

int mainmenu(void)
  {
     char ch;
	 char* mtext = " Please specify the number of the task. \n * You can choose on number from set = {1} \n * Specify \"0\" to exit\n" ;
	 char* errmes = " Error(!) = Main menu does not support this command.\n Make sure that your task number is from menu set of commands and try again. " ;
	 printf("\n%s",mtext );
	 ch = getchar();
	 switch(ch)
     {
		case '0': exit(0);
		case '1': exit(0); break;
		default: printf("\n%s\n", errmes);
	 }
 return 1;
  }
output

 Please specify the number of the task.
 * You can choose on number from set = {1}
 * Specify "0" to exit


 Error(!) = Main menu does not support this command.
 Make sure that your task number is from menu set …
D33wakar 36 Posting Whiz in Training

Thanks alot ! it works :DDDDD Thank you! :DDDDDD

heres the final code in TASM :D

.model small
.stack 100h
.data
a db 0
t1 db,10,13, "Enter a number: $"
t2 db,10,13, "The sum is: $"

.code
main proc
	mov ax,@data
	mov ds,ax

	mov ah, 9
	lea dx, t1
	int 21h

	mov ah, 1
	int 21h  ; to get a single number input from the user
	sub al, 30h ; to make the input number to decimal
	mov a, al ; move the content of al to a variable

	mov ah, 9
	lea dx, t1
	int 21h

	mov ah, 1
	int 21h 
	sub al, 30h

	

	add al, a ; add the contents of al and a
	
	push ax

	mov ah, 9
	lea dx, t2
	int 21h
	
	pop ax
	

	xor ah,ah ;ah=0
	call put_num

	
 
	mov ah,4ch
	int 21h

main endp

 
put_num  proc		;function put_num: prints value stored in  the ax register
			;(a 16 bit integer) to stdout	
	push ax		;save registers
	push bx	
	push cx
	push dx
	xor cx,cx	;cx=0
	mov bx,10d	;bx=10(decimal)
 
PNloop1:xor dx,dx	;dx=0
	div bx		;dx=ax/bx
	push dx		;push the result in stack 
	inc cx		;cx++(cx acts like a counter to notify how many digits in the number) 
	cmp ax,0	;but if the ax was zero,                           
	jnz PNloop1	;then jump to PNloop1                              
	mov ah,2	;otherwise...(Dos function to print a character)   
PNloop2:pop dx		;get the value just pushed in to the stack in dx,  
	add dl,48	;convert it in to ascii 
	int 21h		;and print it		                 				
	dec cx		;decrease counter …
D33wakar 36 Posting Whiz in Training

Remove this line

int mainmenu();

from both 'main' and 'winmain'.
and add a prototype of the function mainmenu at the beginning .

...
int mainmenu(void);

int main()
...
vedro-compota commented: ++ +3
D33wakar 36 Posting Whiz in Training

i found that if i do not add a newline char to the end of fprintf to stdout, it will hang. But if i add the \n it works...

fprintf doesn't print the message until the output buffer is full. To make the prompt to be displayed immediately, you should include '\n' or use 'fflush' like this:

fprintf(stdout,%s,"Hello");
fflush(stdout);//flushes the output buffer

see here(also see the footnote).

D33wakar 36 Posting Whiz in Training

It's a procedure, just call it from your main program like this:

.model small
.stack 100h
.data
a db 0
.code
start:
	mov ax,@data
	mov ds,ax
	mov ah, 1
	int 21h  ; to get a single number input from the user
	sub al, 30h ; to make the input number to decimal
	mov a, al ; move the content of al to a variable
	mov ah, 1
	int 21h 
	sub al, 30h
	add al, a ; add the contents of al and a
	xor ah,ah ;ah=0
	call put_num

	mov ah,4ch
	int 21h

put_num:		;function put_num: prints value stored in  the ax register
			;(a 16 bit integer) to stdout	
	push ax		;save registers
	push bx	
	push cx
	push dx
	xor cx,cx	;cx=0
	mov bx,10d	;bx=10(decimal)

PNloop1:xor dx,dx	;dx=0
	div bx		;dx=ax/bx
	push dx		;push the result in stack 
	inc cx		;cx++(cx acts like a counter to notify how many digits in the number) 
	cmp ax,0	;but if the ax was zero,                           
	jnz PNloop1	;then jump to PNloop1                              
	mov ah,2	;otherwise...(Dos function to print a character)   
PNloop2:pop dx		;get the value just pushed in to the stack in dx,  
	add dl,48	;convert it in to ascii 
	int 21h		;and print it		                 				
	dec cx		;decrease counter
	jnz PNloop2	;if cx not zero (still digits left) then loop again.
			;otherwise ..
	pop dx		;restore registers and return
	pop cx
	pop bx
	pop ax
	ret
end start

Note that the above is a masm code.

D33wakar 36 Posting Whiz in Training

I had written a procedure for displaying integers on the screen a while back, this might help you with your problem.The code is full of comments so I hope you'll not have a hard time figuring out what it does.

put_num:		;function put_num: prints value stored in  the ax register
			;(a 16 bit integer) to stdout	
	push ax		;save registers
	push bx	
	push cx
	push dx
	xor cx,cx	;cx=0
	mov bx,10d	;bx=10(decimal)

PNloop1:xor dx,dx	;dx=0
	div bx		;dx=ax/bx
	push dx		;push the result in stack 
	inc cx		;cx++(cx acts like a counter to notify how many digits in the number) 
	cmp ax,0	;but if the ax was zero,                           
	jnz PNloop1	;then jump to PNloop1                              
	mov ah,2	;otherwise...(Dos function to print a character)   
PNloop2:pop dx		;get the value just pushed in to the stack in dx,  
	add dl,48	;convert it in to ascii 
	int 21h		;and print it		                 				
	dec cx		;decrease counter
	jnz PNloop2	;if cx not zero (still digits left) then loop again.
			;otherwise ..
	pop dx		;restore registers and return
	pop cx
	pop bx
	pop ax
	ret
D33wakar 36 Posting Whiz in Training

I need the value of fd for the futher use.How can I read from file without loosing the fd value?

I haven't understood what you want exactly, but the code below might help you.

#include <stdio.h>
#include <io.h>

int main(void){
	FILE* fp;
	int fd;

	if(fp=freopen("test.txt","w",stdout)){//opened "test.txt" as the 'stdout'
	   puts("Hello, world!");//prints to the file "test.txt"

	   if((fd=_dup(fileno(fp)))!=-1){//fd is another handle to "test.txt"

		   close(fd);//correct form of 'close'
		}
		fclose(fp);
	}
	return 0;
}
D33wakar 36 Posting Whiz in Training
fp = fopen("tmp","r");//in this line fd turns to be 0

I didn't see any fd, there.

freopen("tmp","w",stdout);

Wouldn't it be a good idea to save it's return value(i.e. file handle) somewhere else to use it later.

close(stdout);

'Close' takes an integer representing filehandle to the opened file.

fgets(buf,100 , fp) != NULL );

Aren't you mising something here?

D33wakar 36 Posting Whiz in Training

Im using tasm xD
In command prompt.
what i mean is everytime i want to display it, it display the @,?,A,B,C etc. when the sum exceeds to 10,11,12,13,14 etc

Instead of explaining what you meant, had you posted your code here, you may have already got the solution.

D33wakar 36 Posting Whiz in Training

but what about point between words - it's feature of objective programming , but original c is functional language , isn't it?
if "isn't" how can it be implemented without objective style?

Well, WNDCLASS is a structure defined in 'windows.h' and the contents of a structure are accessed with a dot operator, remember!
See here .

vedro-compota commented: +++++ +3
D33wakar 36 Posting Whiz in Training
double atof ( const char * str );

You need not (and probably should not) do that. Function 'atof' is already declared in the standard library 'stdlib.h' and besides you're not even using it:

numbers[i]=atoi(line);  /* convert string to double float*/

But that's what you should've done, because atoi converts the string to an 'int' type, not a 'double float'.
You should check for errors while opening a file stream, like this:

totalNums = i;
for (i=0 ; i<totalNums ; i++) {
printf("\nThe number %d of %d is: %.0f", i+1, totalNums, numbers[i]);
if((file = fopen("test.txt", "r"))==NULL)  /* open a text file for reading */
        exit(1);//couldn't open the requested file!

And have a good luck with whatever you're trying to do up there.

D33wakar 36 Posting Whiz in Training

When you compile your 'C' code, an object file is generated by the compiler. Such object files from each program(from the collection of programs) are build into a single binary(executabe) file by another program called linker.

D33wakar 36 Posting Whiz in Training

Hi, How to read line by line of text file and store to array C

data.txt example

1234	       25500	24000	1
1345	       23523	21209	5
9865	       12389	   600	98
....

and sorted in order by last column
I try everything and it not working

Thank

Well, Can you show us what you tried?

and sorted in order by last column

I don't have a clue what you're talking about. That's why I'm saying, post your code here, that'll explain everything for you.

D33wakar 36 Posting Whiz in Training

I'm testing this sample fast food chain program and my problem is every time I select the order the resulting price is like Php895764796364227741000000000000000.0000

Your code is incomplete. You're trying to print the resulting price 'TP' without assigning any value to it.

printf("\nMay I take your order?\n");
scanf("%d", &choice);
/* switch statement is missing*/
/*like this */
/*case '1':
     TP=749.00;/* This is called "assigning a value"
     break;
     
  case '2':
     Tp=501.00;
     break;
  ...          */
printf("\nYour bill is Php%f", TP);/*and then print the value*/
D33wakar 36 Posting Whiz in Training
void main(void)

'main' should always return an 'int'(see hereor hereor here,...the list will go "beyond infinity" ).
It's better not to use labels and goto statements as they make your program's control flow hard to follow

goto add;

(see here).Here in your case you can use 'continue' statement, it will do the same thing as you're doing with those 'goto' statements.

clrscr();

and

getch();

These are non-standard functions, so your code is better off without them.As you haven't included "conio.h" header, they will not work anyway.

D33wakar 36 Posting Whiz in Training

i have a question sir/ma'am. My professor wants that the output should be in a table and in a sequence. how can i do that? or that it is not possible?

You mean like this :

for (a=0;a<5;a++){
    for (j=0;j<5;j++)
        printf("%d\t",x[a][j]);
    printf("\n");
}
D33wakar 36 Posting Whiz in Training

I think the problem was the scanf function you were using to read the floating point number. scanf becomes a little bit upset if it doesn't get what it wants.Also use fgets instead of gets if you want to avoid another "segmentation fault" error.

#include <stdio.h>
#include <stdlib.h>
typedef struct cricket{
	char name[20];
	float avg;
	}cri;

int main(void)
{
cri c[3];
int i;
char temp[10];
for(i=0;i<3;i++){
	printf("\n Entr name :");
	fflush(stdout);
	fgets(c[i].name,sizeof(c[i].name),stdin);

	printf("\n Enter his batting average:");
	fflush(stdout);
	fgets(temp,sizeof(temp),stdin);
	c[i].avg=atof(temp);
}

printf("\n\n Name\tAverage\n\n");

for(i=0;i<3;i++){
	printf("\n%s\t%f",c[i].name,c[i].avg);
}

return 0;
}
D33wakar 36 Posting Whiz in Training

&& is more flexible than &

You think so?

Which one is better?

Gosh, I don't know that one.But what I know (up until now) is, those are two different things(though their result may coincide sometimes).The '&' operator is a 'bitwise operator' and returns the result of the operation between the two operands whereas the '&&' is called a logical operator and returns True of false(1 or 0) only.

D33wakar 36 Posting Whiz in Training
D33wakar 36 Posting Whiz in Training

The problem is that you're calling the functions "getPoint" and "continueCraps" with either no arguments at all

getPoint(); // find the point
...
continueCraps();

or insufficient number of arguments.

int point = getPoint(myPoint); // the point is myPoint

See your declarations for these functions

int getPoint(int myPoint, int Balance, int wager); // play's the craps game and returns game status
int continueCraps(int myPoint, int Balance, int wager); // Keep playing craps until a win or loss

They both take three integers as arguments.

D33wakar 36 Posting Whiz in Training


Hey guys, there is an error in this code in fact after encrypting the sentence, i wanted the program to ask if "You want to try again", but i don't know its running the program again without asking the user to input the sentence first and its outputting the array of data !

Help please !

First of all, why aren't you calling those functions from 'main'. Try not to be cool and declare prototypes for each function you use before doing anything else. Because whatever you're doing there is not considered a very good programming habit.

int start(void);
int input(void);
int check(void);

If you want the function to return nothing then, declare it like this:

void start(void);

Even if you want to declare those functions like you did in the above code, you should put return statement at the end of the each one like you usually do with the 'main'.

return 0;

And now for the problem you're facing.
put a "getchar()" after the scanf in the line 96 in your above code and you'll be fine. After the scanf has read your input ,a '\n' is still left in the input buffer. So whenever that scanf(in line 38) tries to take input, it will always get the '\n' left in the input buffer.

D33wakar 36 Posting Whiz in Training

%u is a format specifier for an unsigned integer used in printf and scanf.

D33wakar 36 Posting Whiz in Training

it works perfectly..I just want to understand the logic of how its doing it, specifically:

for(int i = inp.length()-1, j = 0; i >= 0; i--, ++j) dec += (inp[i]-48) * pow((float)base-48, j);

Here,
i= the digit from lower place value to higher place value(initially i=digit in ones' place)
j= the power to which the base is raised to(starts from zero)
And the same old formula of converting a number (in any base ) to the decimal format.
for e.g. in a number with four digits,i starts at 3 and j starts at 0.

...+inp[i-3]*base^(j+3)+inp[i-2]*base^(j+2)+inp[i-1]*base^(j+1)+inp[i]*base^j

Suppose the number is 3751 in base 8,then

3*8^3 + 7*8^2 + 5*8^1 + 1*8^0 = 2025 in base 10

Note: inp-48 converts each char(which is in ascii) to decimal.

D33wakar 36 Posting Whiz in Training

Can you give me an example of what would work for step 4? I don't really understand.

Well, first check if the number is divisible by 2.

as if it isn't divisible by 2, it's not divisible by any other even number.

So,

#include <math.h>//sqrt is defined here.
if(onenumber%2!=0){
    for(count=3;count<=sqrt(onenumber);count+2){//the count need not be greater than square root of onenumber.
        if(onenumber%count==0){
            //is not prime 
        else
           //continue to test
}
else
    //not prime (is even)

Furthermore, check this wikipedia page to improve your knowledge on primality test.

D33wakar 36 Posting Whiz in Training

You might want to add a getchar() after that scanf ,

...
printf("Enter name, price and pages\n");
fgets(b[i].name, 25, stdin);
scanf("%f %d", &b[i].price, &b[i].pages);
getchar();
}
...

After scanf has read your input ,a '\n'(which was typed just after the number) is still left in the input buffer, so we use that getchar to empty the buffer.
scanf() is a bit complex function to handle, especially when taking input interactively from the user. It'll fail to do the job at hand if it doesn't get what it is expecting.Here in your program, user must enter a string followed by a floating point number followed by an integer.If a user fumbled and mistakenly (or intentionally) entered a floating point number instead of an integer, the program will misbehave.
So I'd suggest you to use fgets even also to read the numbers the from user and later convert them using atoi and atof to their respective formats.

D33wakar 36 Posting Whiz in Training

IN line 17, the '%c' should be replaced by '%s' since name is a string(an array of characters) not a single char.
Same thing in line 21 while using printf.
Despite the above changes alot could go wrong with your program. Try using fgets() instead of scanf while taking strings as input.
I just entered "Ban ki Moon" for the 'name' part and your program fell apart.

D33wakar 36 Posting Whiz in Training

how am i supposed to draw a big perpendicular line ?

Perpendicular to what?

is it possible to draw a perpendicular line ?

Drawing a perpendicular line is no different than drawing a simple line like you have drawn above.

D33wakar 36 Posting Whiz in Training

I'm using this code to initialize b pointer
*(b+n)=(char *)malloc(sizeof(char)*20);

That's not called initializing ,it's called dereferencing of b.Dereferencing a pointer always involves the value present at the address pointed to by that pointer.
for e.g.
If there's a pointer 'ptr' to char

char letter1='A'];
char *ptr;

Then you initialize it like this

ptr=&letter1;

and dereference like this:

char letter2=*(ptr);//dereferencing ptr
printf("%c\n",letter2);

Do we have to initialize b and b[n]separately?

Here b is a pointer to a pointer to a char.So b should contain an address of a pointer to a char.
for e.g.

char *letters1="hello",**ptr;
ptr=&letters1;//initializing ptr(letters1 is itself a pointer to a string of char)
char *letters2=*(ptr);//dereferencing ptr
printf("%c\n",*(letters2);//points to the first char of the string "hello"
printf("%c\n",*(letters2+3));//points to the fourth(array's index starts from 0) char of the string "hello"

Now, do you realize what you are missing from the code you posted above?

D33wakar 36 Posting Whiz in Training

I think you're highly mistaken about how functions work.
1.Why are you declaring all the variables as global ?
2.The compiler isn't your math teacher:

x=2(x1+x2);
y=2(y1+y2);

you should explicitly tell the compiler what to do(use '*' operator):

x=2*(x1+x2);
y=2*(y1+y2);

The brackets in c are either used to override the precedence of the operators or in function calls.

3.The function "midpoint"is not returning anything at all, it should return an integer according to your function definition.If it isn't returning anything you should declare it like this:

void midpoint(int ,int);//void means returns nothing

What do you think calling your function "midpoint" will result?
4.Only calling the function from main is not enough, you should save the result somewhere to use it later.

int result = midpoint(x,y);

5. main should always return an 'int'

int main(void)

Here's a tutorial about functions.
Furthermore, you should go through your C Programming book(and the exercises) to fully understand how to create and use functions in c.

D33wakar 36 Posting Whiz in Training

my bad help me convert cout to printf and cin to scanf.. help me pls asap

here you go:

int printf(const char *format, ...)

But you have to include header file "stdio.h"("cstdio.h" if you're compiling as c++) in your code to use printf or scanf.
simple example of printf:

printf("Hello, world!\n")

Here's more about printf and scanf.

Use fgets instead , since scanf is not considered safe.

D33wakar 36 Posting Whiz in Training

Well, I compiled your code and entered the number 119 and it printed out:
" not a prime
Prime number"
Do you need help or just mocking us?
Can you explain the algorithm you're using for this?(only if you're willing to, there's no pressure)

D33wakar 36 Posting Whiz in Training

function stdout prints the string in to the console, so you have to "assemble" (not compile)as a console program to produce an output from the above code.
If you want to "make" a message box then you have to invoke the MessageBox funtion(In that case don't forget to include "user32.inc" and "user32.lib" in your code).

D33wakar 36 Posting Whiz in Training

So , what's wrong with your program ?
since we're not a psychic or in the mood of playing the"Guess what's wrong with my code" game, you have to tell us what exactly are you looking for.

D33wakar 36 Posting Whiz in Training

It's a good thing that you posted your code, but you should compile it first to see if there are any typing errors or syntax mistakes.Here I have posted your code with some corrections.There are comments in each corrected line so you can easily match it with your original code to see where the mistakes were.
You'd better not use the non standard header "conio.h",since it is not portable.getchar() will do same thing as getch(),except you may have to press an extra <enter> key to get the job done.

#include<stdio.h>
#include<conio.h>//don't use this header 

int intpart(float x)
{
 return x;
}

float decpart(float x)
{
 return x - intpart(x);
}

int roundoff(float x)
{
 if(decpart(x) >= 0.5)
 {
 return intpart(x) + 1;/*no space between int and part*/
 }
 else
 {
 return intpart(x);
 }
}

int main()
{
 int arx[100],n,a,b,hs,ls,range,cs;
 int arlow[11], arhigh[11];
 float arcm[11]; //may be you should declare arcm as an array of 11 floats

clrscr(); /*had used colon instead of semicolon, why do you need to clear the console anyway*/
printf("Enter number of scores: "); scanf("%i", &n);

if(n<1 || n > 100)
{
 printf("Invalid no. of scores");
 getch();//use getchar() instead
 return 1;
 }

for(a=0; a<n; a++)
{
printf("%i", a+1);
scanf("%i", &arx[a]);
}

hs = arx[0];
for(a=1; a<n; a++)
{
 if(arx[a] > hs)
 {
 hs = arx[a];
 }
}

ls = arx[0];
for(a=1; a<n; a++)
{
 if(arx[a] < ls)
{
 ls = arx[a];
}
}
range = hs - ls;
cs = roundoff(range / 10.0);//missed semicolon

a=0; …
D33wakar 36 Posting Whiz in Training

Actually i am trying to create some patterns using loop like pascal's triangle etc. But the concept of loop is still not very clear to me as i am learning c language myself without any professional help. would anyone please elaborate me with the help of an example and explain me the reason of each line of code and its functions for better understanding.
THANK YOU............

There are tons of online resources about the loops with examples and the C language as a whole, you might wanna check that out starting from here.(unless you are bounded by some rules or something like that).

D33wakar 36 Posting Whiz in Training

honestly i was new to C and i just need a codes for finding the mean for grouped data. i hope this site can least help me. you have my thanks.

Nobody's gonna provide you a full working code for you, you should write it yourself.This site does help those who "help themselves".
What do you "mean" by "grouped data"?
Have you started yet or you're hoping that someone here will give you the code(not even knowing what you actually want),if the case is latter you're gonna be very disappointed.
In the former case, you might post next time with the exact questions(of where you're stuck in your program and with what exactly you need help with).