Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

You should post your actual error message, because I'm pretty sure that whatever you're seeing is not a segfault.

segfaults happen when you access out of bound array indices, or "garbage" pointers. Your loop contains neither of these things (unless this isn't your real code).

Examples.

The flawed code

$ cat foo.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void foo ( void ) {
  char  *p = malloc(5);
  char  *q = NULL;
  strcpy(p,"hello");    // \0 overflows
  strcpy(q,"world");    // NULL
  // and a memory leak
}

int main ( int argc, char *argv[] )
{
  foo();
  return EXIT_SUCCESS;
}
$ gcc -g foo.c
$ ./a.out 
Segmentation fault

Oh no, it doesn't work - I wonder why.

Use GDB.

$ gdb ./a.out 
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/sc/Documents/coding/a.out...done.
(gdb) run
Starting program: /home/sc/Documents/coding/a.out 

Program received signal SIGSEGV, Segmentation fault.
memcpy () at ../sysdeps/x86_64/memcpy.S:79
79	../sysdeps/x86_64/memcpy.S: No such file or directory.
	in ../sysdeps/x86_64/memcpy.S
(gdb) where
#0  memcpy () at ../sysdeps/x86_64/memcpy.S:79
#1  0x00000000004005b4 in foo () at foo.c:9
#2  0x00000000004005ca in main (argc=1, argv=0x7fffffffe3a8) at foo.c:15
(gdb) up
#1  0x00000000004005b4 in foo () …
Salem 5,265 Posting Sage

> we're actually required to fulfill antispam regulations to keep information about every user who registers with us on record.
You mean this?
http://business.ftc.gov/documents/bus61-can-spam-act-compliance-guide-business
I'm curious about this para

Honor opt-out requests promptly. Any opt-out mechanism you offer must be able to process opt-out requests for at least 30 days after you send your message. You must honor a recipient’s opt-out request within 10 business days. You can’t charge a fee, require the recipient to give you any personally identifying information beyond an email address, or make the recipient take any step other than sending a reply email or visiting a single page on an Internet website as a condition for honoring an opt-out request. Once people have told you they don’t want to receive more messages from you, you can’t sell or transfer their email addresses, even in the form of a mailing list. The only exception is that you may transfer the addresses to a company you’ve hired to help you comply with the CAN-SPAM Act.

How is having two databases (the members AND the ex-members) any safer than having just one list (the members)?

I mean, all it will take is just ONE screwup (either through incompetence or malice) and you're bent over a legal barrel and the system is gonna screw you for everything they can get out of you.

The only reason for having two lists is if you buy in other peoples lists', and you have to cross-check …

jingda commented: Confuse look +0
Salem 5,265 Posting Sage

Anyone with anything genuinely intelligent to add to an old thread would also be smart enough to either PM a mod to suggest the fact, or start a new thread with a backlink, and possibly suggest that threads be merged.

Salem 5,265 Posting Sage

@sergent
http://sourceforge.net/apps/mediawiki/cpwiki/index.php?title=Indentation
I'll comment further when I can stomach reading your code.

> How about something less tricky.
Like for example using a function instead of some hacky multi-line macro.

sergent commented: Thanks lol, I am self-taught programmer so my code doesn't always look pretty. My whole program is much bigger so I just quickly cut & paste small portion of it. +4
Salem 5,265 Posting Sage

Perhaps something like this.

string line;
  while ( getline(file,line) ) {
    istringstream s(line);
    string word;
    while ( s >> word ) {
      cout << line << " ";
    }
    cout << endl;
  }
Salem 5,265 Posting Sage

So which direction is this forum heading in?

On the one hand, happygeek seems to think it's all about the quality. But when it comes to doing something about it, the enthusiasm seems to be more muted

On the other hand, all Dani seems to care about is post and be damned, like the 1-line copy/paste pith of a drive-by sig-spammer is somehow equal to the carefully thought out analysis and response of the regulars in say the C/C++ forums and the virus fixing forum.

I'm sure "909,753 Members" plays very well when setting rates for advertisers.

But somehow the reality is a little different.
Points Earned Today from Activities Worth 1 Point Each
Logging In: 338
That's easy - 338 people have logged in today (it's 4pm here and now, so I guess it's about midday in New York)
That's not many out of the total membership. Probably half of them will be the drive-by's, or short-stay members.

Points Earned Today from Activities Worth 3 Points Each
Replying to Threads: 1,524
So 508 replies so far....
I wonder how much less it would be if posting games and internet scammers were eliminated? Here's an idea, if the management doesn't want to delete those sub-forums, just try "closed for maintenance" for a week or two, just to see what happens.

Points Earned Today from Activities Worth 5 Points Each

Salem 5,265 Posting Sage

Step 1 is learn how to indent code (or at least post indented code on a forum). Your smart IDE editor might be able to make sense of it, but on a forum, it looks like dog food.

Here is your code, courtesy of indent -kr -nut -ts2 -i2 foo.cpp I haven't checked it still compiles, but it looks a lot better.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <math.h>
#include <nurbsS.h>
#include <nurbsSub.h>
using namespace std;

int i, j, l, k, x, y;
float b;
const int maxElements = 15000;
float **Bt, **Btc;
float **M, **MC;
string **T, **TC;

int main()
{
  using namespace PLib;
  NurbsSurface < float, 3 > surf;

  ifstream file("visage.txt");

  Bt = new float *[maxElements];
  T = new string *[maxElements];
  string word;
  i = 0;
  while (file >> word)
  {
    word.size();
    T[i] = new string[word.size()];
    *(T[i]) = word;
    i = i + 1;
  }

  for (j = 0; j < i; j++) {
    Bt[j] = new float[100];
    *Bt[j] = atof((T[j])->c_str());
  }

  for (j = 0; j < i; ++j)
    delete[]T[j];
  delete[]T;

  l = 0;
  x = i / 3;
  M = new float *[x];
  for (j = 0; j < x; j++) {
    M[j] = new float[3];
  }

  for (j = 0; j < x; j++) {
    M[j][0] = *Bt[l];
    M[j][1] = *Bt[l + 1];
    M[j][2] = *Bt[l + 2];
    l = l + 3;
  }

  for (j = 0; j < i; ++j)
    delete[]Bt[j];
  delete[]Bt;

  Matrix < Point_nD < float, 3 …
Salem 5,265 Posting Sage

And what do you suppose they might learn from that spoon-fed answer on a plate?

Don't give away code!
http://www.daniweb.com/software-development/cpp/threads/78223

All that's going to happen is they'll hand this in without having much of a clue, so that when next week's homework comes around (say sorting numbers), they're totally screwed (and back asking for more homework).

WaltP commented: Yep... +16
kvprajapati commented: Yes +15
Salem 5,265 Posting Sage

http://msdn.microsoft.com/en-us/library/dd183411%28v=vs.85%29.aspx
It seems to return a number of different values.

Perhaps you should look at/print the other values as well as just checking for DISP_CHANGE_SUCCESSFUL.

It might give you some clue as to where to start looking next.

Salem 5,265 Posting Sage

http://online.wsj.com/article/SB10001424052748703515504576142092863219826.html
First step would be improving your English.

Talk to a few actual employers in your area to find out what they actually expect from graduates.

Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

Get someone to read these numbers to you, and you try to remember what the highest and lowest numbers you hear.

31
47
85
64
95
48
45
86
26
61
47
76
98
80
62
19
4
12
10
78

Salem 5,265 Posting Sage

I'm getting rather fed up with seeing activity in the geeks lounge, only to find out it's only the terminally bored time-wasters in posting games sub-forum.

If it's not going to be deleted (as per suggestions in other threads), can it at least be made opt-in/opt-out, so that those who don't give a toss what goes on in there don't have to be annoyed by it.

It'll all be over soon...

Salem 5,265 Posting Sage

http://www.dreamincode.net/forums/topic/240357-question-cinema-seating-system-for-project/
How about spending time working on the problem, as opposed to working out where else on the internet you can spam your homework.

Salem 5,265 Posting Sage

> but the text file doesnt appear, whats wrong with this code
1. You're writing binary data, not a text file. So if you try to look at it using say notepad, you'll see garbage.

2. You open the file for writing each time, so ALL previous writes are lost. Perhaps you meant to append?

3. If you're using 'write' of some sort to write a struct as binary data, then you CANNOT have any pointers or STL type objects in your struct.

struct foo {
   int *data;  // bad
   char *message; // bad
   std::string text; // bad
};

Anything like this, and you've just save the pointer, and none of the indirect data it references.

Salem 5,265 Posting Sage

I'd say such questions belong here -> http://www.daniweb.com/software-development/legacy-and-other-languages/42

Though TBH, you'd be better off finding a forum with an actual specialisation in Objective-C, rather than just relying on a couple of people who might know a couple of things.

Salem 5,265 Posting Sage

I wouldn't mind so much if there were some balance between "good" posts and "bad" posts on the end of dead threads.

But as it stands, the ratio is around 1:999 in favour of bad posts.

Bad posts we see repeatedly on a daily basis.
Good posts - well when was the last time you saw one?

jingda commented: Today:) +0
Salem 5,265 Posting Sage

> Signatures don't show up unless you're logged in.
You know that, I know that.

It's the drive-by idiots who sign up, create a profile, post 10 lines of pith in 10 randomly selected posts and then sod off who NEED TO KNOW IT AS WELL.

Is it mentioned anywhere in the signup - I didn't see anything.
A nice "If you were thinking of creating a profile containing sig-links, posting a few times and then leaving, then DON'T BOTHER joining. Spam is deleted and sig-links do not show up in search engines".

I seem to have reported about half a dozen of them just today (just today mind, I've no plan to keep going with this).

Salem 5,265 Posting Sage

This is my three room adventure game

You add more rooms by editing the enum, and adding an extra row in the room array, and changing a few doors in existing rooms to get to the new room.

You might then consider adding say

struct room {
    char    *name;
    int      next[4];   // N,S,W,E from this location
    object  *objects;   // List of things in this room
}

If this is NULL, there is nothing here.

But perhaps you have

struct object {
  struct object *next;
  enum objType;  // objLamp, objAxe, objKey, ...
  char *name;  // "lamp", "axe", "key"
};

Your player struct also has a list of objects collected, which is displayed when you type "inventory". Picking up and putting down is simply moving from the player object list to the room object list.

When you come to open a door, you can check whether the key exists in the player inventory, IF the door happens to be in the locked state.

And so on...

Salem 5,265 Posting Sage

Step 1 is figure out which language you're programming in. This is the C++ forum, and the code you tried to compile was (as far as the compiler was concerned) C++.
What you actually wrote however was all C.

The second step is step back and think about what you're doing.
http://cboard.cprogramming.com/c-programming/88495-development-process.html

Start with some simple functions like

void add_num ( void ) {
  printf("Called add_num\n");
}
void lookup ( void ) {
  printf("Called lookup\n");
}

Now create a simple main which prints a menu, and calls one of the above.
WHEN all that works adequately, then move onto the next little step you can think of.

Oh, and don't neglect indentation (also a mess in your code)
http://sourceforge.net/apps/mediawiki/cpwiki/index.php?title=Indentation

Salem 5,265 Posting Sage

> and ignore the crazy code-formatting problems:
Sorry, that just gets your post ignored.

Nobody here can be bothered to wade through more than a page full of code that was indented by a dancing parrot.

Good indentation will tell you a lot about where it is going wrong without having to read the detail.

Salem 5,265 Posting Sage

> when you could just create a unique namespace and not worry about it?
But don't all namespace names occupy the same namespace?

No doubt there is more than one package out there which uses say the 'graphics' namespace. Trying to use two packages with badly chosen generic names could be a challenge.

How do you ensure uniqueness, without a central (cumbersome) registry?

For a small price, I suppose using a namespace derived from a domain name would suffice.

Using UUID's may be unique (and free), but it's cumbersome to write using namespace NS_5798323769944ad3b9c7ca3f5079704b; or NS_5798323769944ad3b9c7ca3f5079704b::myFunction();

Salem 5,265 Posting Sage

> I want to make a Program that takes two inputs one initial number and one final number for example if I input 1 as the beginning number and 13 as the final,
So make it
Or at least figure out how to google "fibonacci sequence".

Salem 5,265 Posting Sage

http://msdn.microsoft.com/en-us/library/ms686298%28v=vs.85%29.aspx
Sleep(), without all the verbiage at the start.

Salem 5,265 Posting Sage

http://msdn.microsoft.com/en-us/library/aa379166%28v=vs.85%29.aspx
If you're calling it the first time to retrieve the length of the name, then you should pass NULL for the name, and make sure the length is initialised to zero.

Otherwise, you're passing a pointer to a string in read-only memory, and it attempts to write 1 byte to it (and tells you you can't as a result).

Salem 5,265 Posting Sage

http://www.virtualhelp.me/linux/164-dos2unix-missing-ubuntu-1004
Depending on your distro, find and download something called 'dos2unix'

Salem 5,265 Posting Sage

# while( !infile.eof() )
Don't use eof() to control the loop
http://sourceforge.net/apps/mediawiki/cpwiki/index.php?title=Feof

When you copied the data file, did you copy it in binary mode, or text mode?
That is, did you convert the \r\n line endings of windows into the \n line endings of Linux?

Use the debugger to see if all the strings you're reading have \r at the end (on Linux).

Salem 5,265 Posting Sage

Don't forget to mention where else you posted, so that we don't waste OUR time saying what has already been said.

You might be considerate to post a link back here on the SO site.

Salem 5,265 Posting Sage
skilly commented: 1 bad apple... +0
Salem 5,265 Posting Sage

> Last edited by syria718; 24 Minutes Ago at 09:15. Reason: i cant'n post perfectly sorry,,
It seems you still can't - you still haven't figured out [code]
[/code] tags.
How many hints do you need to do this?

Salem 5,265 Posting Sage

Compare your usage with this example perhaps (IANAWP)
http://msdn.microsoft.com/en-us/library/zaewt3xs%28v=vs.80%29.aspx
Note specifically the MAKEINTRESOURCE

You might also check that AfxGetResourceHandle() is actually returning what you think it should (even though the manual page doesn't indicate any error condition).

Salem 5,265 Posting Sage

Well it would help if you could post code with a decent approach to indentation

It also helps to remove all the commented out code you accumulated, at least for the purposes of posting it on a forum.

Something like this.

#include <iostream>
#include <fstream>
#include <string>
#include <nurbsS.h>
#include <nurbsSub.h>
#include <math.h>

using namespace std;

int i, j, l, k, x, nU, nV;
float b;
float Bt[10000], Btc[10000];
float M[10000][3];
float Mc[10000][2];
string T[10000];
string TC[100000];

int main()
{
  using namespace PLib;

  std::ifstream file("visage.txt");
  std::string word;
  i = 0;
  while (file >> word) {
    T[i] = word;
    i = i + 1;
  }

  for (j = 0; j < i; j++) {
    Bt[j] = atof(T[j].c_str());
  }

  l = 0;
  k = 0;
  x = i / 3;
  cout << "i=   " << i << endl;
  cout << "x=   " << x << endl;
  for (j = 0; j < x; j++) {
    M[j][k] = Bt[l];
    M[j][k + 1] = Bt[l + 1];
    M[j][k + 2] = Bt[l + 1];
    k = 0;
    l = l + 3;
  }

  Matrix < Point_nD < float, 3 > > Pts(x, 3);
  for (j = 0; j < x; ++j) {
    Pts(j, 0) = M[j][0];
    Pts(j, 1) = M[j][1];
    Pts(j, 2) = M[j][2];
  }
  cout << "point   " << "j  =" << j << Pts(0, 0) << endl;

  std::ifstream fileuv("a1.txt");
  std::string worduv;
  i = 0;
  while (fileuv >> worduv) {
    TC[i] = worduv;
    i = i + 1; …
Salem 5,265 Posting Sage

> And if you could be very specific.
Kinda ironic, given that your post is about as vague as it is possible to get, and still remain comprehensible English.

How about posting some actual code you TRIED?

FWIW, my first thought is you've screwed up over ANSI/UNICODE and your indiscriminate casting to make the compiler STFU has resulted in you trying to manipulate UNICODE strings (where every alternate byte is \0), as an ANSI/ASCII array of bytes, where all those UNICODE \0's make for some very short strings.

Salem 5,265 Posting Sage

> Getting Error after installing Turbo C.... how to rectify this problem.
Well you could complain to your school, and get them to spend THEIR time and money on supporting obsolete tech (you paid them, one way or another, make them earn it).

Whilst some of us know how to solve your problem, few of us care enough to bother helping with this issue.

Consider it a form of passive resistance. If your school gets to feel the full impact of every student complaining about this old crap, then they might just do something about it. If we continue to help with TurboC issues, it just enables your school to do nothing.

Or you could just install a modern compiler - read my sig links for why.
http://www.microsoft.com/express/Downloads/
http://www.smorgasbordet.com/pellesc/
http://www.codeblocks.org/

Salem 5,265 Posting Sage

> so keep adding the sum and carry, until carry becomes 0.
Yes, you basically write the code for what the hardware looks like
http://en.wikipedia.org/wiki/Adder_%28electronics%29

Salem 5,265 Posting Sage

Sure, why not.
It's as good an approach as any other, and you'll learn some things doing it.

In fact, solving the SAME problem in several different ways is also a good way to learn how to answer "what is the best way to solve this problem" questions for yourself.

sknake commented: i would have just said english +0
Salem 5,265 Posting Sage

n printf is a fuction in header file <iostream.h> to print some output on console.....it considers from right to left while printing..(helpful to know when u r using more than one increment/decrement operator within a single printf statement))

ALL of this is BS.

First, printf isn't in iostream.h, it is in stdio.h (or cstdio if you're using c++)

As for expression evaluation order, go and read this:
http://www.daniweb.com/software-development/c/threads/210533
It's a list of WILDLY different results from running the SAME code on DIFFERENT compilers, all caused by writing broken code which has undefined and unspecified behaviours.

Salem 5,265 Posting Sage

Perhaps you should start with the language(s) you know.

Any complete language will in principle do the job. Mostly, it will depend on YOUR skill with a particular language.

Salem 5,265 Posting Sage

> Hey, i found quite a few methods to ADD TWO NUMBERS WITHOUT USING THE + OPERATOR
Do any of them actually work over the full range of integers the same as regular addition would?

This method fails miserably on all negative numbers.

Salem 5,265 Posting Sage

It's because eax is used as the return value register.

If you look at the assembly for a normal function, you'll see a move TO eax when the function returns, and a move FROM eax in the caller, to assign the destination variable.

Salem 5,265 Posting Sage

What were YOUR answers?
Then we can correct your mistakes and fill in the blanks.

Whereas at the moment, it looks like begging for some spoon-feeding.

Salem 5,265 Posting Sage

Are we supposed to guess what OS you're using, or what _write is supposed to do?

http://linux.die.net/man/2/write
If it's this "write", then the second parameter needs to be a POINTER to some memory, not the munged result of your calculation.
No wonder it crashes.

Salem 5,265 Posting Sage

> Turbo c++ problem!
Pressing ALT-F4 might be a better option, followed by

- delete fossil compiler from system
- install one (or more) of these fine modern compilers.
http://www.microsoft.com/express/Downloads/
http://www.smorgasbordet.com/pellesc/
http://www.codeblocks.org/

kvprajapati commented: They don't want to change their toolset. +15
Salem 5,265 Posting Sage

OK, so this morning I see that the folder icon in the forum list is yellow, meaning there is something unread since my last visit.

In I go, and there is a big fat "You can only see threads that you have started"

I haven't started anything there, so why is it telling me there is something unread?

jonsca commented: You must not have your Little Orphan Annie decoder ring from Ovaltine +0
Salem 5,265 Posting Sage

How about

int colours[3] = { RED, YELLOW, BLUE };
textcolor(colors[rand()%3] + BLINK);

Now add a loop around that, perhaps more colours in the array and maybe even a gotoxy and you're done.

Salem 5,265 Posting Sage
for ( i = 0 ; i < N ; i++ ) {
  // read data
  // if condition, break
}

If N is 10, and you exit after 2 entries, how much data should you read?

for ( i = 0 ; i < N ; i++ )
// or
for ( i = 0 ; i < 2 ; i++ )

When you understand that the 2nd answer is right, replace the 2 with a variable.

Salem 5,265 Posting Sage

Lines 66 and 81, you're examining the WHOLE array, not the number of valid entries entered.

If you had a separate variable which you increment ONLY when the data is valid, you would know when to stop.

Salem 5,265 Posting Sage

Looks like this and this, with a new username.

Show us what you managed to figure out so far, so we only have to fill in the gaps (as opposed to giving you everything, which simply won't happen).

kvprajapati commented: +1 +15
Salem 5,265 Posting Sage

> X-Originating-IP: [41.138.178.89]
This is the big giveaway sign

http://www.ip-adress.com/ip_tracer/41.138.178.89
P address [?]: 41.138.178.89 [Whois] [Reverse IP]
IP country code: NG
IP address country: Nigeria
IP address state: Lagos
IP address city: Lagos

Mmm, Nigeria, home of the 419 scammers.