And here's how you use strtok (you know... for future references).
[CODE]#include

include

int main(void){
char line[20] = "Process0 12 1"; // suppose this is the first line read by fgets
char delim=" ";
char
result = NULL;
result=strtok(line,delim);
if(result != NULL)
printf("process:%s\n",result);//store process in an array
result=strtok(NULL,delim);//first argument NULL except first call to strtok
printf("quanta:%s\n",result);//store quanta in another array,you can use atoi to change
//quanta to integer type

result=strtok(NULL,delim);//first argument NULL except first call to strtok
printf("priority:%s\n",result);//store priority in another array

return 0;
}
[/CODE]

[QUOTE]The program runs and compiles. When I enter the two words, it gives me a bunch of random stuff when printing[/QUOTE]That's because scanf is not used like this
[CODE]scanf(x1,x2,MAXFORTHIS,stdin);[/CODE]
[URL="http://en.wikipedia.org/wiki/Scanf"]click here[/URL]

[QUOTE]Can you tell me why use size_t and not int for orig_len and rep_len?[/QUOTE]
Using size_t instead of just plain int or unsigned int makes your code more portable since the size of int types vary across platforms.
Also the above standard functions expect their third argument to be of size_t type.
[CODE]char stpncpy(char restrict s1, const char restrict s2, size_t n);
int strncmp(const char
s1, const char *s2, size_t n);[/CODE]

[QUOTE][CODE]fflush(stdin);[/CODE][/QUOTE]Didn't you read my previous post ? How many times do I have to tell you that you should not use fflush() with stdin.In the c standards, it is only defined to use with the output streams.
[QUOTE]I have another problem with the following program I have tried which tests if sides form a right angled triangle or not. [/QUOTE]First of all, if you have another problem and the current problem is resolved then you should mark this thread URL="http://www.daniweb.com/community-center/daniweb-community-feedback/threads/226710"]"solved"[/URL] and open another thread with the new problem.[QUOTE]First of all, is there any unnecessary repetition? [/QUOTE]Actually, that's your job to figure it out since you know your level of expertise and how compact you need your program to be.You can use functions to make it more short and compact.
[QUOTE]Is there any simple way by which I can add a reply feature to the program?
[/QUOTE]That is as simple as you can get.[CODE]if(Condition)
printf("Something");
else
printf("something else");[/CODE]

[QUOTE]oh I get the point then. So, in other words it fflush can be used instead of always creating a double getchar() in the end of each prog. [/QUOTE]
No, you don't. I've already said that fflush() should not be used with input streams, it is made to use with output streams only.People usually use getchar() at the end to consume the data that might be left in the input buffer. That could be replaced with this[CODE]while (((ch = getchar()) != '\n') && (ch != EOF))//has no body ;[/CODE]But still at least a character is left in the buffer.

[QUOTE]Am i correct if I understand I/O buffer
as the temporary memory stored/inputted in the variables? [/QUOTE]
see [URL="http://en.wikipedia.org/wiki/Data_buffer"]here[/URL].[QUOTE].but what is its use here?[/QUOTE]Just to make sure that everything in the buffer is written immediately after you call printf and not after sometimes when you're taking inputs from the user. Believe me it happens(or may not,it depends on the compiler you're using or the system you're running on), usually when you're trying to take inputs and give outputs subsequently.This happens because buffers are flushed out only when they're full or a newline is encountered or fflush() is called.

[QUOTE]This is a piece of code from some book.[/QUOTE]Is that [URL="http://www.daniweb.com/software-development/c/threads/389911/1679633#post1679633"]the same book[/URL] Narue told you to burn ?
[CODE]int fun (const union employee e);
union employee
{
char name[15];
int age;
float salary;
};[/CODE]You should declare the union first and then the function 'fun'.
[CODE]union employee{
char name[15];
int age;
float salary;
};
int fun (const union employee
);//in function prototypes, you only mention the argument type[/CODE]
[CODE]void main()//so wrong[/CODE]According to the standards, main() returns an int type[CODE]int main(void)[/CODE]
[QUOTE]but this code is running on turbo C giving just a error message of const to * conversion ????? please tell me whether this code is right ??????[/QUOTE]How could that be?If the compiler issues an error message then the code should not have compiled in the first place.And yes the code is wrong!If you have used 'const' Type qualifiers then that means that you're declaring them as constants and they should not be modified during runtime.
Quote drom c-faq.com
[QUOTE]A const value is one you promise not to modify. The compiler may therefore be able to make certain optimizations, such as placing a const-qualified variable in read-only memory. However, a const-qualified variable is not a true constant; that is, it does not qualify as a constant expression which C requires in certain situations, such as array dimensions, case labels (see section 18.3.1 below), and initializers for variables with static duration (globals and static locals). [/QUOTE]
Quote from linux man page
[QUOTE]const is used to tell the compiler that the data ...

[ICODE]'fflush(stdout)'[/ICODE] forces the data (if any)in the I/O buffer to be written to the screen .Including a '\n' character(if suitable) in the [ICODE]'printf'[/ICODE] itself also does the same thing.[CODE]printf("incorrect value\n");[/CODE]Remember that [ICODE]fflush[/ICODE] is only used with output streams.Calling [ICODE]fflush[/ICODE] with [ICODE]NULL [/ICODE]argument flushes all the opened streams.

[QUOTE]The code compiles[/QUOTE]That totally amazes me.[QUOTE] but when I run the program it stops responding once it enters the while loop [/QUOTE]So there's a strong possibility that the problem lies on your while loop statement.
[QUOTE][CODE] while (fgetc(inFile) != EOF) != NULL) {[/CODE][/QUOTE]'fgetc' returns EOF when read error occurs or the EOF is reached.So this is enough[CODE]while(fgetc(inFile)!=EOF)[/CODE]But wait a minute, the file pointer you declared has a name 'inputFile'.Also that you're using fgetc just to detect the EOF seems a bad idea to me.Instead just read the whole line at a time and extract the information you need one by one.

[QUOTE][CODE] BYTE PTR [BX+SI][/CODE]What does this do exactly though? [/QUOTE]Si is an index register, though in the above code SI always remains zero since you had only one character (to access) in the string.While using instructions like CMP and ADD, you need to use the pointer directive 'BYTE PTR' to tell the assembler that the pointer contains a 8-bit value(or you want to access a byte). Similarly, there are other directives like 'WORD PTR','DWORD PTR' etc.So the above code is equivalent to
[CODE=C]char ptr="A";//BX points to the character in the buffer just like ptr here
int i=0;//SI is similar to this i
printf("%c\n",
(ptr+i));//prints the character
[/CODE]

[QUOTE]Tell me why the compare always goes to my error message please.[/QUOTE]
See line 42 in your code.[CODE]LEA AX, DATASTR ;Move the character into the AX register[/CODE]It is actually copying the offset address of 'DATASTR' to AX, not the character itself.Instead do like this:[CODE]LEA BX,DATASTR ;load the addr of character into the BX register
MOV SI,0 ;SI=0
CMP BYTE PTR [BX+SI],'A' ;Compare the character to 'A'
JB ERRORMSG ;If the character is below 'A' then go to error message
CMP BYTE PTR[BX+SI],'a' ;Compare the input character to lowercase 'a'
JB TESTCAPITAL ;Jump below if the character is less than 'a'
[/CODE] Here, BX is used to load the offset address, because it's the only general purpose register allowed to do so in real mode assembly.
Similarly, your 'TESTCAPITAL' will look like this:[CODE]TESTCAPITAL:
CMP BYTE PTR [BX+SI],'Z';Compare the input character to uppercase 'Z'
JA ERRORMSG ;If the character is in the no-man-land part of the chart, display error.
JB CONLOW ;If it's between capital 'A' and 'Z' then convert to lower!
[/CODE]and your CONLOW
[CODE]CONLOW:
ADD BYTE PTR[BX+SI], 20H;CONVERT from upper to lowercase!
mov AH,06h ;DOS function to print a character
mov DL,[BX+SI] ;Print the character
INT 21H
[/CODE]If you want to use [CODE]MOV AH,09H
LEA DX,DATASTR
INT 21H[/CODE] then, you have to setup your buffer like this:
[CODE]MAX DB 2 ;maximum input length
ACTUAL DB ?
DATASTR DB 1 DUP(' ') ;size is inputlength+2
DB '$' ;end of string(required to use AH=09H function)[/CODE]
Do that and we'll see.
P.S. It ...

[QUOTE]Would I loop until the user presses the enter key with no input? [/QUOTE]
I'm assuming that your program takes in a character(a-z or A-Z) and displays a character as output(and your c++ sample is doing the same thing). Here's the pseudocode(well.., kind of.)
[CODE]-take user input
-if input==10(i.e.'\n'), then exit the program.
-if 65 <= input <= 90 then change it to lower case and print it and then jump back to take another input
-if 97<= input >= 122 then change it to upper case and print it and then jump back to take another input
-else then print the warning message, and again loopback to take the input.[/CODE]
The [URL="http://www.asciitable.com/"]ascii [/URL]table might come in handy.
[QUOTE]How would I test that condition using the proper syntax?[/QUOTE]
here's an example :[CODE]mov ah,8 ;dos function to get a character, the character is stored in 'al'
int 21h ;most important interrupt in dos,executes a system call to perform the above function
cmp al,10d ; check if user pressed key
je warning ;then print the warning message
;je means 'jump if equal' and 'warning is a label' [/CODE]
Here's the [URL="http://www.unixwiz.net/techtips/x86-jumps.html"]intel x86 jmp instruction reference[/URL] for you.

just use [CODE]char bus
char
dest
.../and later/
bus="single-decker"
dest="taiping"[/CODE]

[QUOTE]Now, if anyone would be willing to assist me I would greatly appreciate it! [/QUOTE]I don't know what you need help with, since you have it all figured out.If you want us to write(or translate) your code for you, the forum rules wouldn't allow it.

You have to use software [URL="http://en.wikipedia.org/wiki/Interrupt"]interrupt[/URL]s to get input from keyboard and to print output to the screen. See [URL="http://www.cs.cmu.edu/~ralf/files.html"]Ralph Brown's Interrupt List[/URL].
Do some research on how to do your assignment and write your code.Post your code here even if it's broken, we'll help you to fix it.
Cheers and happy coding!

[QUOTE][CODE]for(c_5=1; c_5<=10;c_5++)
{
for(c_6=c_5;c_6>=1;c_6--)
printf(" ");
for(c_6=10;c_6>=c_5;c_6--)
printf("*");
printf("\n");
}
printf("\n");
getch();[/CODE][/QUOTE]
initialize c_5 to 0 instead of 1.
[CODE]for(c_5=0; c_5<=10;c_5++)[/CODE]

[QUOTE].for some reason sorting resets all entries to blank.Why is it doing that? I compare two entries, swap if necessary. Trying to figure out where that's failing.[/QUOTE]I compiled and ran your program, It works fine.
In my opinion, in your 'DeleteEntry' function, try matching only the user's phone number, because even if I entered a correct firstname with incorrect surname(which is not in the phonebook), then the entry for which the first name matched will be deleted.As there may be some users whose surname or firstname or both matches with each other.But that's only my opinion.

[QUOTE][CODE]int main( int argc, char *argv[] ) {//Wrong[/CODE][/QUOTE]
[CODE]int main( int argc, char
argv[] ) {//right[/CODE]

[QUOTE]It shows the same prompt multiple times[/QUOTE]That's because the 'printf' statement is inside the loop and you don't need to pass that 'i'.You can do like this:
[CODE]int main (void)//this is more readable, isn't it?
{
int n, smallest=0, i=0;
printf ("Enter a list of positive integars:\n");//printf outside the loop
while (scanf("%d", &n)!=EOF){//press ctrl+Z to break out of the loop
if(n==-1)
break;
if (n<=smallest)
smallest=n;
i++;
}

printf("The smallest among the %d integars is %d.\n ",i,smallest);

return (0);

}[/CODE]

[QUOTE][CODE]void print_triangle_info(int area(), int perimeter());
void print_square_info(int area(), int perimeter());[/CODE][/QUOTE]
Are 'area' and 'perimeter' functions? If not, why give parentheses after them.the correct form of prototyping will be:
[CODE]void print_triangle_info(int, int);
void print_square_info(int,int);//takes two integers as arguments and return nothing(void)[/CODE]
and then their definitions
[CODE]void print_triangle_info(int area, int perimeter) {//no parentheses after area and perimeter
//Now make use of the area and perimeter to print "triangle info"
}[/CODE]
and then call them from 'main'
[CODE]int main(void) {
//calculate area and perimeter here or create functions to calculate them outside the 'main'

print_triangle_info(area, perimeter);
print_square_info(area, perimeter);
}[/CODE]
edit:
@ WaltP- Wow, that was quick!

minimi commented: Thank you for the heads up! +2

[QUOTE=hufo17][CODE]int ok = 0;
for (x=0;x<=2;x++)
{
y=0;
y++;
if(c[x][y] ==d[x][y])
ok = 1;
}[/CODE][/QUOTE]
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
[CODE]for(x=0;x<2;x++)
for(y=0;y<2;y++)
if(c[x][y]==d[x][y])
//rest of the code...[/CODE]

[QUOTE=hugo17][CODE]int a,b;
a = b;//[COLOR="Red"]bad practice[/COLOR][/CODE][/QUOTE]
[QUOTE=hugo17][CODE]char c[2][2];
char d[3][3];
c = d;[/CODE][/QUOTE]Well?Why don't you try that in your compiler? the answer is no. you cannot do that with arrays.
[QUOTE=hugo17][CODE]// or can you compare two arrays to get a true or false statement?
if ( c == d)[/CODE][/QUOTE]
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.
[QUOTE=hugo17][CODE]// or if I want to know if two signs in an array are equal:
if ( c[1][2] == d[1][2])[/CODE][/QUOTE]This is the correct form.
[QUOTE=hugo17]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?[/QUOTE]
Suppose you have an array [CODE]int array[5][/CODE]
then you can assign values to them like this
[CODE]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.[/CODE]

In addition,
You can remove this line
[CODE]#include //non- standard library,also not portable[/CODE]
'main' should always return int, like this:[CODE]int main(void)[/CODE] and return statement at the end.[CODE]return 0;[/CODE]

add[CODE]fflush(stdout);[/CODE]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:
[CODE]fgets(name[i],sizeof(name[i]),stdin);[/CODE]

[QUOTE=Phillamon;1669659]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.

[CODE]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[/CODE]

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[/QUOTE]
In line 24..
You can not use[B] cmp[/B] with both operands being a memory variable. Instead use an immediate value[CODE]cmp number,14d ;the immediate value must be the second operand[/CODE]
or you can also do
[CODE]cmp al,max[/CODE]

[QUOTE]...that's your homework [/QUOTE]
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.
[QUOTE]I'm thinking that your solution was the following for line 9.
[CODE]printf("%d", matrices[Index][i])[/CODE][/QUOTE]
No, it was not.
It was this:
[CODE]printf("%d",matrices[i]);[/CODE]
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'
[CODE]matrices [Index] = (int ) malloc( size sizeof(int));[/CODE]
And you only got the first member because 'Index' in your 'Display' function always remains zero.
So you can also do like this:
[CODE]for (Index = 0; Index <= size; Index++)
{
printf("%d", matrices[Index]);
}[/CODE]
And also I can't believe that [B]someone who has done several projects[/B] is still [B]having trouble understanding the concepts of pointers and then applying them[/B]?

[QUOTE=vedro-compota]I don't understand - why compiler allows such code = [/QUOTE]
You can do like this then.
[CODE]#if defined(_WIN32)||defined(_WIN64)

//Windows specific includes and code goes here..

elif defined(linux)

//linux specific includes and code goes here..

endif[/CODE]

[QUOTE]I now am having a problem entering values into the dynamic memory.[/QUOTE]
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.
[QUOTE]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.[/QUOTE]
The problem is in your 'Display' function (in line 9 of your second code-see carefully) and that's your homework.

[QUOTE=Ancient Dragon]That means he is using a different compiler than you are. Just ignore it.Pelles C has no such option. [/QUOTE]
Yes, it does.
Actually if "Enable Microsoft Extensions" option is unchecked, then compiler will issue the message:
[CODE]If you are compiling a Windows program, make sure you use the /Ze option!
[/CODE]
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.
[QUOTE=vedro-compota]but the winmain() is the entry point for windows program.....
why compiler doesn't compiler such code = [/QUOTE]
This example code may help you, it compiles as a 'win32' EXE.
[CODE]#include

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

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.
[CODE]#include

if defined(_WIN32) || defined (_WIN64)
include
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;
}[/CODE]
[CODE]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 of commands ...

[QUOTE=inagumi;1667173]Thanks alot ! it works :DDDDD Thank you! :DDDDDD

heres the final code in TASM :D

[code]

.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 ...

Remove this line
[QUOTE][CODE]int mainmenu();[/CODE][/QUOTE]
from both 'main' and 'winmain'.
and add a prototype of the function mainmenu at the beginning .
[CODE]...
int mainmenu(void);

int main()
...[/CODE]

vedro-compota commented: ++ +3