A little bug just change the Exit func to
void * Exit(void * ptr)
{
char c;
while (1)
{
scanf("%c", &c);
if ( c == 'e')
breakLoop = 1;
}
}
A little bug just change the Exit func to
void * Exit(void * ptr)
{
char c;
while (1)
{
scanf("%c", &c);
if ( c == 'e')
breakLoop = 1;
}
}
This is just an idea how can solve your problem
#include "stdio.h"
#include "pthread.h"
pthread_t threadEvent;
unsigned char breakLoop = 0;
void * Exit(void * ptr)
{
char c = 'a';
scanf("%c", &c);
if ( c == 'e')
breakLoop = 1;
}
main()
{
int i = 0;
pthread_attr_t attr;
char * arg = NULL;
pthread_attr_init(&attr);
int threadID;
threadID = pthread_create(&threadEvent, &attr, Exit, arg); // create thread wich recives user input
while(1)
{
printf("%d\n",i++);
if (breakLoop)
break;
sleep(1);
}
return 0;
}
So the logic is that you create a thread wich will take input from user :).
Adopt this code for your compiler. I dont have conio.h so I used scanf instead of getch. But avoid scanf. Modify sleep with usleep. Compiled with gcc.
And the answer is:
###################################################
# author: Andor Pásztor
###################################################
#################################################
# text segment #
#################################################
.text
.globl main
main:
la $a0, str1
li $v0, 4
syscall
li $v0, 5
syscall
or $t0, $v0, $v0
la $a0, str2
li $v0, 4
syscall
li $v0, 5
syscall
add $t1, $v0, 0
la $a0, str3
li $v0, 4
syscall
li $v0, 5
syscall
add $t2, $v0, 0
add $t7, $t0, $zero
startMul: # mult loop
blez $t7, endMult
add $t3, $t3, $t1
add $t4, $t4, $t2
sub $t7, $t7, 1
j startMul
endMult:
sub $t5, $t3, $t4
la $a0, str4
li $v0, 4
syscall
move $a0, $t5
li $v0, 1
syscall
li $v0, 10
syscall
#################################################
# data segment #
#################################################
.data
str1: .asciiz "input a = "
str2: .asciiz "input b = "
str3: .asciiz "input c = "
str4: .asciiz "The result is "
Compare it with yours and you will see the differences:
###################################################
# author: Andor Pásztor
###################################################
.text
.globl __start
main: ##execution starts here
#--------------------Start Cut---------------------
la $t1, str
nextCh: lb $t2, ($t1)
beqz $t2, strEnd
addi $t4, $zero, 0x61
sub $t3, $t2, $t4
bgez $t3, l1
add $t2, $t2, 32
sb $t2, ($t1)
l1: add $t1, $t1, 1
j nextCh
strEnd: la $a0, ans
li $v0, 4
syscall
la $a0, str
li $v0,4
syscall
la $a0, endl
li $v0, 4
syscall
li $v0, 10
syscall
#--------------------End Cut-----------------------
###################################################
# data segment #
###################################################
.data
str: .asciiz "ABCdEfgH"
ans: .asciiz "lowercase string ="
endl: .asciiz "\n"
I have a question for you. Did you try to debug your code with SPIM simulator? If answer is no then try it.
You mean functions? Try to find open source decoders (very hard process) wich decode the file and send the raw pcm data to audio device. Writing decoder on your own without experiance is insane. Wish you luck
OH never noticed that
post the code maybe the array is not the problem
i just bet ya too it i returned month n year instead of those values thnks for ur help
#include <stdio.h>
#include <string.h>
#include <ctype.h>
//#include "ansidecl.h"
//#include "safe-ctype.h"
#define TRUE 1
#define FALSE 0
#define EXIT_SUCCESS 0
#define BUFF_SIZE 255
/************************************************** **************************
* Function readRestOfLine() is used for buffer clearing. Source:
* https://inside.cs.rmit.edu.au/~sdb/teaching/C-Prog/CourseDocuments/
* FrequentlyAskedQuestions/
************************************************** **************************/
void readRestOfLine()
{
int c;
/* Read until the end of the line or end-of-file. */
while ((c = fgetc(stdin)) != '\n' && c != EOF);
/* Clear the error and end-of-file flags. */
clearerr(stdin);
}
char* getUserInput(char *prompt)
{
char *result;
char buff[BUFF_SIZE];
unsigned char i;
unsigned char len;
printf(prompt);
result = fgets(buff, BUFF_SIZE, stdin);
if(result == NULL)
{
printf("Error please enter the input again!\n");
}
else if(result[strlen(result)-1] != '\n')
{
readRestOfLine();
}
len = strlen(result);
for (i=0; i<len-1; i++) //
if (!isdigit(result[i]))
return NULL;
return result;
}
int validateMonth(unsigned month)
{
if(month<0 || month>12) /* flag 1 for true*/
{
printf("Month error 0 or less or equal to 12 please\n");
return FALSE;
}
return TRUE;
/*return 1;*/
}
/************************************************** **************************
* Function getMonth() prompt the user for a number MIN_MONTH to MAX_MONTH and
* returns that number. The number 0 is valid because this indicates that the
* user wants to select all months.
************************************************** **************************/
unsigned getMonth()
{
/*** declare variables*/
char *prompt = "Please enter a month between 0 - 12 !\n";
char *month;
int valMonth;
int monthValid = -1;
do
{
monthValid = TRUE; …
In getMonth() and getYear() dont return EXIT_SUCCESS
does it have anything to do with the $sp or the $fp registers? I can't seem to find anywhere information on what these registers actually do.
Use this pdf. The $fp and $sp registers are explained in "Procedure Calls"
link
http://www.cs.wisc.edu/~larus/HP_AppA.pdf
Post the problem to linux forum or try to search the solution trought other linux forums (which will give you faster time to solve the problem). I'm sure that the problem occured to others.
thankx for your kind reply,
i will try to create file with .cpp extension and try to compile it with the given command i also want to know more about knoppix can you tell me more about programming in knoppix or can you give me reference website which can be useful for me to develope my skill.
On google I found many links (typed KNOPPIX). Use google and find links wich are interesanting to you. For example maybe this link is interesanting
http://www.shockfamily.net/cedric/knoppix/
http://distrowatch.com/table.php?distribution=knoppix.
For programming try to search linux programming on google. Here are some links for compilers
http://www.stat.uchicago.edu/~gosset/Compdocs/gcc.html
http://www.cs.wm.edu/cspages/computing/tutorial/gpp.html
Hope that this help
addi $t0, $s0,48
beq $t1, $t0, L1
L2: lw $t1, 16($t0)
srl $t2, $t1,3
bne $t2, $t0, L2
L1: sw $t2, 32($t1)
ori $s0, $s0, 0xFF7F
j L1if the machine code equivalent to the above MIPS codes is loaded in memory at starting address 0xd24fc91c, wat exact binary values will be used in the address/offset fields of the machine code for the instructions beq, bne and j?
Use SPIM simulator to find out
You can't load word
lw $t1, 5($s1)
becouse 5 isn't divisable with 4 so you also can't do this
addi $s1, $s1, 11
and then
lw $t3, -8($s1)
the rest is correct so $t0 is 0xFFFFFF9d and $t2 is 0x000000fa. For learning MIPS you can use SPIM (yes revers from MIPS) simulator.
Whole asm code
# FAKULTET TEHNICKIH NAUKA NOVI SAD
# KATEDRA ZA RACUNARSKU TEHNIKU I MEDJURACUNARSKE KOMUNIKACIJE
#################################################
# text segment #
#################################################
.text
.globl main
main: # ovde pocinje izvrsavanje
la $s1, dat1
lb $t0, 5($s1)
# lw $t1, 5($s1) # greska (error)
addi $s1, $s1, 11
lbu $t2, -8($s1)
# lw $t3, -8($s1) # error
#################################################
# segment podataka #
#################################################
.data
dat1: .byte 0xad 0x59 0xae 0xfa 0xaf 0x9d 0xb0 0xa6 0xb1 0x78 0xb2 0x04 0xb3 0xbc 0xb4 0x88 0xb8 0xff
##
##
Use some editor to create example x.cpp.
Then try to compile with g++ -o x x.cpp (without additional library) and run it with ./x command. Type this lines in console. If error occures then use google to check them. I think that knoppix has gcc and g++ included in it.
You have errors what's this
private:
int const ArraySize;
int const [40];
int intConversion(char);
void CopyArray( int[], const int[]);
int const [40] :?: do you mean int number[40]. Try to fix the errors
if you want between 1 and num (num not included) than
/* lab3.cpp Working with Functions
*/
#include <iostream>
#include <math.h>
using namespace std;
/* function isPrime (int num) finds out whether the input integer num is a prime number or not.
If num is a prime, return true; else return false;
A prime number is a number whose only factors are 1 and itself.
Note: 0 and 1 are not prime numbers. The minimal prime number is 2.
*/
bool isPrime (int num)
{
for (int fac = 2; fac <= num; fac++)
if ((num % fac == 0) && (num != fac))
return 0;
return 1;
}
/* function printPrimes (int num) prints all the prime numbers between 1 and num
*/
void printPrimes (int num)
{
int number = 2;
while(number < num)
{
if (isPrime(number))
cout << number<<" ";
++number;
}
}
/* function getMaxPrime(int num) returns the greatest prime number between 1 and num.
if there is no prime number between 1 and num, getMaxPrime() should return a 0.
*/
int getMaxPrime (int num)
{
int maxCount = 0;
for (int count = 1; count < num; count++)
{
if (isPrime(count))
maxCount = count;
}
return int (maxCount);
}
int main ()
{
int number;
do
{
cout <<endl<<endl
<<"Please enter a number, 0 or negative to stop :";
cin >> number;
if (number > 0)
{
cout << "All the prime numbers between 1 and "<< number<<" are: "<< endl;
printPrimes(number);
cout << …
i'm not sure if I understood the problem but try to replace
if (num % fac == 0)
with
if ((num % fac == 0) && (num != fac))
and use this
void printPrimes (int num)
{
int number = 2;
while(number <= num)
{
if (isPrime(number))
cout << number<<" ";
++number;
}
}
instead your printPrimes
I didn't had the time to test it
in first example counting the words at the begining of every word, in second example counting the words at following space (0x20). Try to add space after 'project'.
one of the way is cin.getline but you must specify the delimiter (maybe '.')
#include <iostream.h>
void main()
{
char str[20];
cin.getline(str, 20, '.');
cout << str << endl;
}
Maybe U should try with switch
.
.
.
cin>>c;
switch(c)
{
case 1:
cout<<"Enter the number of dice to roll...";
cin>>n;
cout<<"in groups of how many? ";
cin>>g;
D4(n,4);
break;
.
.
.
default:
cout<<"That is not a valid selection!\n"<<"\n";
break;
}
and also try to avoid globals