gerard4143 371 Nearly a Posting Maven

In C++

day = 'p'

is the assignment operator not the comparison operator...You want

day == 'p'

See line 57

gerard4143 371 Nearly a Posting Maven

Here's a solution but it assumes a few things
1. Your passing a c-string...I use strlen() which requires a c-string
2. The c-string passed has room for the extra character.

#include <stdio.h>
#include <string.h>

char* append_it(char *cptr, const char c)
{
	int len = strlen(cptr);
	cptr[len + 1] = cptr[len];
	cptr[len] = c;

	return cptr;
}

int main()
{
	char test[10] = {'A','B','C','\0'};

	fprintf(stdout, "new c-string->%s\n", append_it(test, 'D'));
	fprintf(stdout, "new c-string->%s\n", append_it(test, 'E'));
	return 0;
}
gerard4143 371 Nearly a Posting Maven

Firstly

char* test = "ABC"

creates a read only c-string so you can't modify it...

You want something like

char test[10] = {'A','B','C','\0'};

gerard4143 371 Nearly a Posting Maven

Try running this code

#include <stdio.h>

int one, two;

int main()
{
	printf("Enter two numbers->\n");
	scanf("%d - %d", &one, &two);
    
	fprintf(stdout, "one->%d, two->%d\n", one, two);
	
	return 0;
}

First enter your numbers like this

34 56

and then try entering your numbers like

34 - 56

Try this link

http://www.java-samples.com/showtutorial.php?tutorialid=564

gerard4143 371 Nearly a Posting Maven

See if you can find what I changed...

#include <stdio.h>

int NumericalAnswer;
int score = 0;

int main()
{
	    printf("Question 1: What's 4 x 3?\n");
	    scanf("%d", &NumericalAnswer);
    
	if (NumericalAnswer == 12)
	{
		printf("You got it right!");
		score += 1;
	}
	return 0;
}
NichtSoGut commented: Couldn't really have been more helpful!! +0
gerard4143 371 Nearly a Posting Maven

By size? Do you mean height or weight?

gerard4143 371 Nearly a Posting Maven

Because its syntactically illegal. Check this link...

http://www.neu.edu.cn/cxsj/materal/otherc/imada/subsection3_6_2.html

gerard4143 371 Nearly a Posting Maven

"I heard in class that dynamic arrays like in java aren't supported"

Hmmmm, yes they are. Try a vector.

gerard4143 371 Nearly a Posting Maven

I know this is probably radical but why don't you write some code, like below, and try it yourself.

#include <stdio.h>
#include <stdlib.h>

struct mystr
{
	unsigned int a;
	unsigned int b;
	unsigned int c;
}thestr[3] = {{0,},};

int main(int argc, char**argv)
{
	int i;

	for (i = 0; i < 3; ++i)
	{
		fprintf(stdout, "a->%u\n", thestr[i].a);
		fprintf(stdout, "b->%u\n", thestr[i].b);
		fprintf(stdout, "c->%u\n", thestr[i].c);
	} 	
	exit(EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

I'm not familiar with mac but I would ensure that you have a proper file path and the permissions to create a file.

gerard4143 371 Nearly a Posting Maven

A few things...First what doesn't work? Next you should check to see if fopen was successful.

dblPoint = fopen(BINDATA, "wb");

Did fopen succeed or fail here?

gerard4143 371 Nearly a Posting Maven

Ok, so I'm leaving my struct-based date idea. I'll pass the data directly in a sequence of write().

Thank you for the reply.

You should really check the XDR library, it'll make passing data through a network a snap.

http://docs.sun.com/app/docs/doc/816-1435/6m7rrfn9b?a=view

gerard4143 371 Nearly a Posting Maven

The easiest way is the functionality in the XDR library(eXternal Data Represention) or if your not familiar then you could pass non c-string data by passing the start address and the length...Like this.

unsigned int mydata = 1234;

write(clientfd, &mydata, sizeof(mydata));

Please note, you cannot pass pointers and expect the receiver to use them without failure....You must pass the data that the pointer points to..

gerard4143 371 Nearly a Posting Maven

The biggest thing that I see is line 30 you call calcData() but downpayment, mort_gage, loan are uninitialized..

gerard4143 371 Nearly a Posting Maven

I only quickly looked at your code...I couldn't find a != operator for decimal.

gerard4143 371 Nearly a Posting Maven

I see one potential problem here. You have a forward declaration class Retriever..Which makes me wonder??? If you have a Alsation object and call your friend function which has a reference to a Retriever how do you intend to handle the fact that your data members may deficient for a Retriever?

It seems to me that this function would make more sense as a non-friend/non-member function defined after both Retriever and Alsation.

gerard4143 371 Nearly a Posting Maven

Because its aligned 2 bytes its guaranteed that the address & 0x1 will return 0...Check out the attached code..

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char**argv)
{
	int i = 0;
	char __attribute__((aligned(2))) ch1;
	char *cptr = &ch1;

	for (i = 0; i < 20; ++i)	
	{
		fprintf(stdout, "ans->%u\n", ((unsigned int)(unsigned long)cptr & 0x1));
		cptr += 2;
	}


	exit(EXIT_SUCCESS);
}

The output is ans->0 for all iterations...Why do they have a function that tests for this? I really don't know.

sree_ec commented: thanks :) +1
gerard4143 371 Nearly a Posting Maven

Actually I made the reply before coffee...These remarks indicate

/*
085 * Note that all tvec_bases are 2 byte aligned and lower bit of
086 * base in timer_list is guaranteed to be zero. Use the LSB for
087 * the new flag to indicate whether the timer is deferrable
088 */

That your masking out the bit of struct tvec_base *base with 0x1 and returning the value.

gerard4143 371 Nearly a Posting Maven

To see what's just do some substitution...

#define TBASE_DEFERRABLE_FLAG (0x1)
struct tvec_base *base

First we cast base to unsigned long
(unsigned long)base

Then we perform the bit operation & on
(unsigned long)base & 0x1

Then we cast our result to
(unsigned long)(unsigned long)base & 0x1

Why do it this way? It may be a simple trick to manipulate the spinlock_t variable in

struct tvec_base {
         spinlock_t lock;
         struct timer_list *running_timer;
         unsigned long timer_jiffies;
         struct tvec_root tv1;
         struct tvec tv2;
         struct tvec tv3;
         struct tvec tv4;
         struct tvec tv5;
} ____cacheline_aligned;

Note I said 'may' be a way.

gerard4143 371 Nearly a Posting Maven

I don't know why your allocating memory because s1 is supposed have enough room to append s2 onto it..

Here's a simple example that came with my help files

char*
           strncat(char *dest, const char *src, size_t n)
           {
               size_t dest_len = strlen(dest);
               size_t i;

               for (i = 0 ; i < n && src[i] != '\0' ; i++)
                   dest[dest_len + i] = src[i];
               dest[dest_len + i] = '\0';

               return dest;
           }
gerard4143 371 Nearly a Posting Maven

And also, it wont let me use getline(cin, input, '@@@'), if I try to enforce that condition.

Thanks in advance.

That's because the delimiter has to be a character....'@' is a character but '@@@' is not.

Why did you post your C++ question in the C section?

gerard4143 371 Nearly a Posting Maven

This function strcpy() expects c-strings not characters

strcpy(array1[n],array);

array1[n] and array are characters.

gerard4143 371 Nearly a Posting Maven

I think if you look closely, you'll find that your switch statement is outside your loop.

This is your for loop

for (i = 0; i < 32; ++i)
		grade[i] = 0;

To include the switch you'll need to add braces like

for (i = 0; i < 32; ++i)
{
grade[i] = 0;
switch(something)
{...}
}
gerard4143 371 Nearly a Posting Maven

If this points to a structure..

process *state_of_queue = fcfs(q);

Then use

state_of_queue->structure_member

or

(*state_of_queue).structure_member

gerard4143 371 Nearly a Posting Maven
gerard4143 371 Nearly a Posting Maven

Thanks myk45 for your help.

Now, about the second question.. I don't want to allocate less of bytes, but lets say I did that.. why it won't return a segmentation fault?
I just want to understand what is going on if I allocate less bytes..

It probably depends on you memory manager and how it doles out memory.

gerard4143 371 Nearly a Posting Maven

If this is a custom environment then you'll probably have to create a special linking/compiling process so your exe will execute.

In truth I'm not really sure what your after? The boot floppy, is it one you created or is it one you downloaded? The kernel I have the same questions, is it one you created or is it one you downloaded?

gerard4143 371 Nearly a Posting Maven

Ooops I double posted by accident...Can a moderator remove this one..Thanks.

gerard4143 371 Nearly a Posting Maven

I'm guessing its the p[p] part. Well its simple if you break it down..

We'll look at the inner p which just returns the i-th element of the array. The value from the inner p is used as the 'index value' of the outer p[index value]. Its a little unorthodox to use an array this way.

gerard4143 371 Nearly a Posting Maven

What line(s) are you having problems with?

gerard4143 371 Nearly a Posting Maven

If you insist on doing it this way then try the string's [] operator.

int i = fullName.length();
cout<<"Your reversed full Name is: ";	
while (i>=0)
{
   cout<<fullName[i];
   i--;
}

Please note that the string object has iterators which would handle this problem nicely.

gerard4143 371 Nearly a Posting Maven

Please get out of the habit of using gets(), its a very dangerous function. A much better solution is fgets().

Also...

Your while statement assumes that the fetched c-string is 80 characters long?

while(i!=80)

shouldn't it be

while(i <= strlen(array))

Also this next line is incorrect

if(array[i]==(('a')||('A')||('e')))

It should be

if ( array[i] == (('a') || array[i] == ('A') || array[i] == ('e')))

Plus we have move vowels than 'a' and 'e'

gerard4143 371 Nearly a Posting Maven

Because that's the size of the pointer and not the size of the c-string. Try displaying the pointer with

std::cout << (void*)p << std::endl;
gerard4143 371 Nearly a Posting Maven

Could it be the new line character in the fgets() fetched c-string.

gerard4143 371 Nearly a Posting Maven

'It gives me a "bad_alloc" error when the obj is instantiated.'...Which object?

gerard4143 371 Nearly a Posting Maven

I tried compiling your code but you have MS specific functionality....scanf_s doesn't work with Linux...

gerard4143 371 Nearly a Posting Maven

Could you post an example of the file or post the shell script?

gerard4143 371 Nearly a Posting Maven

If you know how to test for one blank...then test for another one?

gerard4143 371 Nearly a Posting Maven

Which operating system?

gerard4143 371 Nearly a Posting Maven

I know how to solve this in Linux using GCC but the solution is not portable...That said you should be able to use the concept which is....wrapping the C++ functionality in a C calling sequence, see below

testit.cpp

#include <iostream>

extern "C" void PrintStr(char *str);

void PrintStr(char *str)
{
	std::cout << "From Cpp Object file->" << str << std::endl;
}

testit.h

void PrintStr(char *str);

test.c

#include "testit.h"

int main()
{
	char ch[] = "From the C program";

	PrintStr(ch);
	return 0;
}

And my compile lines

g++ -Wall -ansi -pedantic -c testit.cpp
gcc testit.o test.c -o test -Wall -ansi -pedantic -lstdc++

Note the inclusion of the standard C++ library with the -lstdc++ switch..Hope this helps.

Output:

From Cpp Object file->From the C program

gerard4143 371 Nearly a Posting Maven

The question is...What were you expecting? Was it something like below

#include <iostream>
#include <cstring>
using namespace std;

int main(int argc, char* argv[])
{
	unsigned char p[] = {'1', '1', '1', '1'};

	unsigned char a[4];

	for(int i = 0; i < 4; i++)
	{
		 a[i] = ~(p[i] - '0');
	}
	for(int i = 0; i < 4; i++)
	{
		 cout << (unsigned int)a[i] << endl;
	}

}

Which produces

254
254
254
254

gerard4143 371 Nearly a Posting Maven

Well once for erek and once for the copy of erek in the function call.

gerard4143 371 Nearly a Posting Maven

yeah i know this tutorial and i try it out but it did not work

I wrote something like this but didn't use C++, I used asm(16 bit) plus had to write my own linker script to get it to work...

Projects like this are very interesting and the end result is generally a very simple exe that will boot the computer...I would try ams if your really interested in pursuing this.

Here's another link..

http://linuxgazette.net/77/krishnakumar.html

gerard4143 371 Nearly a Posting Maven

Do you mean, how does a C object file that has been linked into a C++ project, retrieve/accept the GUID of an object?

gerard4143 371 Nearly a Posting Maven

I'm not certain which binutils(binary utilities) are valid/available with that version but I would Google around and find out...

You could try

nm filename

Which should display all the symbols from the object file

Here's a link for a list of the GNU GCC compilers binutils

http://www.gnu.org/software/binutils/

gerard4143 371 Nearly a Posting Maven

Ooops I assumed your were running a Linux based system with Executable Linkable Format(elf)..Are you compiling this on Windows or Linux/Unix and what binutils are available?

gerard4143 371 Nearly a Posting Maven

Try creating a small exe with the gcc compiler then use the binutil

readelf -a exename

It should display all the information you need..

gerard4143 371 Nearly a Posting Maven

Two c-strings are identical if, the starting addresses are the same or if different(starting addresses) the characters that constitute the c-string are the same.

gerard4143 371 Nearly a Posting Maven

First question. What is t[] an array of, characters? I ask because you pass 1 as the size in your write function.

Second question...You have

int val;
read(fd[0],&val,1);

val is an integer...its size should be sizeof(int)...e.g.

read(fd[0], &val, sizeof(int));

Third question...Well more of a pointer

write(fd[1],t,1);

should be

write(fd[1],&t,sizeof(whatever t is));

gerard4143 371 Nearly a Posting Maven

I'm a little confuse...Do you want a program that will take an inputted binary number and then produce its decimal equivalent?

e.g.

enter a binary number->111
ans->7

Is that what you want?