homework

Print the first line of a file

void cabclh(){ FILE *fp; char *val, aux; int i=0; char *result, cabeca[60]; fp=fopen("trabalho.txt","r"); if(fp==NULL){ printf("Erro ao abrir o ficheiro\n"); return ; } val=(char*)calloc(aux, sizeof(char)); while(fgetc(fp)=='\n'){ fgets(cabeca,60,fp); prin...

Accessing every child class of parent class in Java

Hi All, I have to implement a logic whereby given a child class, I need to access its parent class and all other child class of that parent class, if any. I did not find any API in Java Reflection which allows us to access all child classes of a parent class. Is there any way to do it? Ex. class B extends class A class C extends class ...

What does a compiler do?

I have two questions.... 1) What does a Java Compiler actually do? 2) Why do we need compilers? ...

Assembly LC3: How to read input without "input a character" being printed to the display?

I'm writing an assembly language program using lc3 and when I run trap x23 (IN) the message "input a character" comes up. I want it to come up saying Please enter an integer between 1 and 15: but it ends up like this: Please enter an integer between 1 and 15: input a character: Help please ...

GoTo statements and alternatives in VB.NET

I've posted a code snippet on another forum asking for help and people pointed out to me that using GoTo statements is very bad programming practice. I'm wondering: why is it bad? What alternatives to GoTo are there to use in VB.NET that would be considered generally more of a better practice? Consider this snippet below where the us...

Simple, Custom Parsing with c++

Hi! I have been reading SO for some time now, but I truly cannot find any help for my problem. I have a c++ assignment to create an IAS Simulator. Here is some sample code... 0 1 a 1 2 b 2 c 3 1 10 begin 11 . load a, subtract b and offset by -1 for jump+ 11 load M(0) 12 sub M(1) 13 sub M(3) 14 halt Using c++, I ne...

NoClassDefFoundError when running Netbeans 6.8 application

My application has recently started throwing NoClassDefFoundError errors when I am running my application from within NetBeans. It never used to do this. And when I run this outside of NetBeans using the command line argument that it provides once built, these errors are not produced Is this a bug with Netbeans? I have reinstalled Ne...

C programming - Print the 3rd line of a txt

Hi...Imagine that i have on a txt this: Hello SLB 3 1324 how can i get the 3rd line? fgets or fscanf? and imagine on a txt this: 8;9;10;12 how can i print the numbers separeted? ...

questions on nfa and dfa..

Hi Guys... Hope you help me with this one.... I have a main question which is ''how to judge whether a regular expression will be accepted by NFA and/or DFA? For eg. My question says that which of the regular expressions are equivalent? explain... 1.(a+b)*b(a+b)*b(a+b)* 2.a*ba*ba* 3.a*ba*b(a+b)* do we have to draw the NFA and DFA an...

Find a repeated numbers out of 3 boxes

I have 3 boxes, each box contain 10 piece of numbered paper (1 - 10) but there is a number the same in all 3 boxes eg: box1 has number 4 and box2 has number 4 and box3 also has number 4. How to find that repeated number in java with an efficient/fastest way possible? ...

java array manipulation

Hi, I'm a beginner in java. I want the logic of the small program. I have two arrays array = {a1,a2,a3,a4,a5,,,,,,,,,an} and array2 = {b1,b2,b3,b4,,,,,,,,,,,bn} I want string as a1b1,a2a3b2b3,a4a5a6b4b5b6,.... so on up to n Please tell me what will be the logic. ...

regular expression for bit strings with even number of 1s

Let L= { w in (0+1)* | w has even number of 1s}, i.e. L is the set of all bit strings with even number of 1s. Which one of the regular expressions below represents L? A) (0*10*1)* B) 0*(10*10*)* C) 0*(10*1)* 0* D) 0*1(10*1)* 10* According to me option D is never correct because it does not represent the bit string with zero 1s. But ...

Graph Tour with Uniform Cost Search in Java

Hi. I'm new to this site, so hopefully you guys don't mind helping a nub. Anyway, I've been asked to write code to find the shortest cost of a graph tour on a particular graph, whose details are read in from file. The graph is shown below: http://img339.imageshack.us/img339/8907/graphr.jpg This is for an Artificial Intelligence class,...

Java, LinkedList of Strings. Insert in alphabetical order

I have a simple linked list. The node contains a string (value) and an int (count). In the linkedlist when I insert I need to insert the new Node in alphabetical order. If there is a node with the same value in the list, then I simply increment the count of the node. I think I got my method really screwed up. public void addToList(No...

How to solve this problem with lists?

what i don't understand in my task here what kind of list i can use, and if it should have 2 attributes key and value ? or only value? with pointers to another node ofc the task: "design a function which create a list using input from the keyboard _ the prefered solution. Assume that some magic stops the input; so the length of a list i...

Scheme. Tail recursive ?

Hi guys, any tail-recursive version for the below mentioned pseudocode ? Thanks ! (define (min list) (cond ((null? list) '()) ((null? (cdr list)) (car list)) (#t (let ((a (car list)) (b (min (cdr list)))) (if (< b a) b a))))) ...

how to Calculate number of address bits needed for memory?

Hi I am preparing my exam for computer system. I don't quite understand how to calculate the number of address bits needed for the memory. For example, Suppose that a 1G x 32-bit main memory is built using 256M x 4-bit RAM chips and this memory is word-addressable. What is the number of address bits needed for a memory module? What...

Collaborative kernel development

Hi, I have to develop a patch for the linux kernel (2.6) for an university course I'm attending. I have to develop this patch with a friend of mine and we need to edit the same files on our computers (2-3 PCs). So, we want to use something like a collaborative editor and/or a version control system. The problem is that we never used some...

C SIGSEGV Handler & Mprotect

I'm constructing a program which uses mprotect() to restrict a block of memory from accessing. When the memory is requested, a SIGSEGV is thrown which I listen for using a signal() call. Once the SIGSEGV has been detected, I need to somehow access the pointer to the memory that was requested (that threw the fault) and the size of the s...

new >> how would i read a file that has 3 columns and each column contains 100 numbers into an array?

int exam1[100];// array that can hold 100 numbers for 1st column int exam2[100];// array that can hold 100 numbers for 2nd column int exam3[100];// array that can hold 100 numbers for 3rd column int main() { ifstream infile; int num; infile.open("example.txt");// file containing numbers in 3 columns if(infile.fail...