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

include <string.h>

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=Gribouillis;1728291]If you want to use s, write
[code=python]
s = [x for x in s if x!= 'r']

or

s = list(x for x in s if x!= 'r')
[/code]
there is a small difference with s[:] because this code create a new list for the name s. With s[:] it only fills the same list object with new elements. For example try this
[code=python]
a = ['b','a','r','r','i','s','t','e','r']
b = a
c = a
b = [x for x in b if x != 'r']
print a
c[:] = [x for x in c if x != 'r']
print a

print id(a), id(b), id(c)
[/code]
If you want to learn more about generator expressions, read about generators and the iterator protocol in the python documentation, but you can postpone this a little if you are new to python.[/QUOTE]
Thanks for the quick reply, I really appreciate it.

[QUOTE]Conclusion: don't modify the size of a list while iterating on this list, use a copy if necessary.[/QUOTE]yes using a copy solves the problem thank you but I have couple of questions about the second method.
If I understood correctly [CODE]s[:] = (x for x in s if x != 'r')[/CODE]means reconstruct the list s from the components of the list s itself (interating through them ) but skip the element 'r' right?
Also why can't we use just s instead of s[:].
[CODE]s=(x for x in s if x!= 'r')

s
<generator object <genexpr> at 0xa80ff54>
[/CODE]

If there's a list like below
[CODE]s=['b','a','r','r','i','s','t','e','r'][/CODE]
and if I tried to remove every 'r' from the list like this
[CODE]>>> for x in s:
if(x=='r'):
s.remove(x)[/CODE]
it gives the following result.
[CODE]>>> s
['b', 'a', 'i', 's', 't', 'e', 'r'][/CODE]
Why isn't the last 'r' removed from the list.

[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="

[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="

[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="

[QUOTE]This is a piece of code from some book.[/QUOTE]Is that [URL="

[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="

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="

[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]fflush(stdin); //clear the buffer???![/CODE][/QUOTE]Don't use [ICODE]'fflush'[/ICODE] with [ICODE]'stdin'[/ICODE],[URL="

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

Though, the thread has been marked solved, I would like to point few things out. [QUOTE=hkdani]If you don't want to mess with getting rid of the '\n', then just use gets.[/QUOTE]No, never use 'gets()' while taking strings as input([URL="

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

In addition,
You can remove this line
[CODE]#include <conio.h> //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]