Jump to content

Wikipedia:Reference desk/Archives/Computing/2010 December 10

From Wikipedia, the free encyclopedia
Computing desk
< December 9 << Nov | December | Jan >> December 11 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


December 10

[edit]

Strings

[edit]

Currently, I am taking lesson on "Strings". I couldn't run the following program. Got an alert signal on line 13:if ( strcmp ( name, "Nahid" ) == 0 ) // Equal strings

#include <iostream> // For cout
#include <iostream> // For the string functions

using namespace std;
int main()
{
    char name[50];
    char lastname[50];
    char fullname[100]; // Big enough to hold both name and lastname

    cout<<"Please enter your name: ";
    cin.getline ( name, 50 );
    if ( strcmp ( name, "Nahid" ) == 0 ) // Equal strings
       cout<<"That's my name too.\n";
    else
       cout<<"That's not my name.\n";
     // Find the length of your name
     cout<<"Your name is "<< strlen ( name ) <<" letters long\n";
     cout<<"Enter your last name: ";
     cin.getline ( lastname, 50 );
     fullname[0] = '\0';            // strcat searches for '\0' to cat after
     strcat ( full name, name );    // Copy name into full name
     strcat ( full name, " ");      // We want to separate the name by a space
     strcat ( fullname, lastname ); // Copy lastname onto the end of fullname
     cout<<"Your full name is "<< fullname <<"\n";
     cin.get();
}

How could I fix that? Thanks--NAHID 00:08, 10 December 2010 (UTC)[reply]

What alert did you get? Nimur (talk) 00:12, 10 December 2010 (UTC)[reply]
Could it be that you got "undefined identifier: strcmp"? Because you didn't #include<cstring>, but iostream twice. --Tardis (talk) 00:23, 10 December 2010 (UTC)[reply]
Visual C++ auto-included that header. I got an error on full name - which probably should be fullname. Nimur (talk) 00:31, 10 December 2010 (UTC)[reply]
  • The alert shows a square shaped red box, but it did not explain anything to me. It only disappears if the sentence is fixed. I checked and wrote that line (13) again but it seems that problem did not go away. The box is still popping up.--NAHID 10:21, 10 December 2010 (UTC)[reply]
Put your mouse over the alert-box. A small arrow will appear to the right of the box; click on the arrow. A dialog box showing what the error is will be displayed. Or select View/Output (Ctrl+W, O), which will open a new window showing all the compilation errors and warnings. CS Miller (talk) 14:57, 10 December 2010 (UTC)[reply]
You may be getting a warning that strcmp is deprecated and that strncmp is recommended instead. APL (talk) 00:40, 11 December 2010 (UTC)[reply]
You do realise you have the same error ('full name' rather than 'fullname') in two consecutive lines? AndyTheGrump (talk) 01:05, 11 December 2010 (UTC)[reply]

Running WCII on a CF48

[edit]

Whenever I try to run Warcraft II on my laptop (an old Panasonic Toughbook), I get the opening cinematic, but when the main menu comes up, it just shows as a blank screen. Alt-tabbing nets me a screen with blue lines running down it. I have no idea why it's acting like this (and yes, I do have the CD in the drive); any ideas?

For the sake of having the most complete info, this laptop is running Windows XP Pro (SP3), has a clock speed of 896 MHz, and has a total of 256 MB RAM. —Jeremy (v^_^v Hyper Combo K.O.!) 05:08, 10 December 2010 (UTC)[reply]

Any ideas at all? —Jeremy (v^_^v Hyper Combo K.O.!) 01:07, 11 December 2010 (UTC)[reply]
Run it under DOSBox? It is, after all, an old DOS game. 118.96.154.34 (talk) 17:20, 11 December 2010 (UTC)[reply]
The issue with that is that my desktop has no problem running the game, and it, too is an XP Pro SP3 rig. —Jeremy (v^_^v Hyper Combo K.O.!) 21:00, 11 December 2010 (UTC)[reply]

torrent download

[edit]

i recently downlaoded a torrent file and started the download, it went smoothly for about 2 hours, and i switched off the computer and when i switched it on again, the download doesn't continue. i mean, it shows downloading under the status tab, but there's no speed under the speed tab, remaining time is infinity. it's never happened with me before... is it a bad torrent??? can i do anything about it????

thanx —Preceding unsigned comment added by 117.197.240.5 (talk) 09:39, 10 December 2010 (UTC)[reply]

It could mean some of the people (or even just one person) you were downloading from also turned their computers off for a while. How many seeds and peers are showing for the download? Probably if you just leave the download going all the time it will catch when the other people reenter the swarm and start downloading again. There's nothing more you can do at your end but wait. 82.44.55.25 (talk) 10:34, 10 December 2010 (UTC)[reply]

usb ports

[edit]

I plug an external hd (one partition, 250 GB): At first the pc (xp home, centrino) recognize it, after some minutes it behaves as I had unplugged it.. t.i.a. --217.194.34.103 (talk) 10:36, 10 December 2010 (UTC)[reply]

Could be a number of things. Failing drive, poor connector, ... After my own experience, the first I'd try is to leave the computer untouched with the drive plugged in. Does the drive stay online longer? If yes, that could indicate that small vibrations when you type etc are jiggling the connector, giving a poor electrical connection. Try to isolate the problem: if you have several USB ports, try another; if you have several cables, try another; if you have access to another computer, try the drive there. Does accessing the drive constantly make things better or worse (I'm thinking overheating vs. the drive going to sleep mode). Once upon a time I had an external drive that was failing by overheating; making a table fan blow on it helped me rescue the files. 88.112.59.31 (talk) 18:50, 10 December 2010 (UTC)[reply]
USB cable too long or USB cable wrapped around power or other cables causing interference. Does the HD have a separate power supply or does it get the power from the USB port; if the latter, then the port may not be providing enough power; use a powered hub, use a power supply with the HD if it has a connector or use a special USB Y cable to connect it to two USB ports for more power. ---— Gadget850 (Ed) talk 18:58, 10 December 2010 (UTC)[reply]

Black screen

[edit]

I have a Compaq Presario CQ60 that wont boot, when I turn it on the power light comes on and the HDD light at the front flickers but nothing happens. I connected it to another laptop using a VGA cable to see if it was the screen that was broken but get the same blank screen on the other laptop. Anyone any suggestions on what I could do to try to solve this thanks. Mo ainm~Talk 14:08, 10 December 2010 (UTC)[reply]

It's no use connecting 2 laptops together and expecting one to display the other's output. You should try connecting it to a monitor. --86.133.83.252 (talk) 14:36, 10 December 2010 (UTC)[reply]
I tried that also and nothing but the black screen. Why would it make a difference between a monitor and another laptop? Mo ainm~Talk 14:47, 10 December 2010 (UTC)[reply]
The VGA connectors on laptops are for output only, if they receive an incoming signal (like you're trying to do) they wouldn't know what to do it, hence nothing appears.  ZX81  talk 15:17, 10 December 2010 (UTC)[reply]
Thanks for that explanation wsn't aware of that. But as I say I tried it on my PC monitor and nothing appeared. Mo ainm~Talk 15:19, 10 December 2010 (UTC)[reply]
You might need to enable the external monitor. The symbol is normally a hollow box with square brackets around it. Turn of the laptop and monitor. Connect the monitor, turn the monitor on, and finally turn the laptop on. Then press the button. You might need to hold down the Fn button as well. CS Miller (talk) 16:38, 10 December 2010 (UTC)[reply]
No, think I didn't get my question across properly the problem is that the laptop is not booting and all I get is a black screen I only connected it to another monitor to check if the screen was broke on the laptop it isn't so it is some other problem and this is what I am trying to discover. Mo ainm~Talk 16:57, 10 December 2010 (UTC)[reply]
What does the machine sound like as it starts up? Do the fans start? Do they stop again? Does it do any beeping (beep codes are used to indicate problems that occur in early stages of booting)? It's probably not a screen problem, assuming that you mean that the HDD light flickers on briefly and then stops, because otherwise it be flickering constantly for a couple minutes. Paul (Stansifer) 18:09, 10 December 2010 (UTC)[reply]
Yes the HDD is spinning and yes it is the HDD light at the front that flashes, it doesn't stay on or stay off. Mo ainm~Talk 18:21, 10 December 2010 (UTC)[reply]
Then maybe it is booting properly. Start it up, wait for a while, hook up the monitor. The monitor may take a few seconds to recognize an input source. Then hit Fn+F5 (or whatever controls the VGA out status) and see if that changes anything. Paul (Stansifer) 22:42, 10 December 2010 (UTC)[reply]
I'm inclined to agree with the others, that this sounds more like a display problem than a failure to boot (which would normally result in some text-only error messages being displayed). However, it may not be the monitor, but the graphics card that's at fault. Unfortunately, as most laptops aren't "user serviceable", this means a trip to the repair shop is needed. One other possibility, going back to the monitor being the issue, is that the LCD back-light may not be functional. Try shining a bright light at the monitor, at a shallow angle, in an otherwise dark room, to see if you can make out any text. If so, then you know that's the problem. I had this happen with one laptop, and I had to open it up to just the right angle to get the back-light to work. StuRat (talk) 07:59, 13 December 2010 (UTC)[reply]

Iterating through arrays

[edit]

Instead of having to write "for n = 1 to x : j(n)=k(y): next n", which languages allow you to write something like: "iterate j()=k(y)"? Thanks 92.15.0.115 (talk) 14:58, 10 December 2010 (UTC)[reply]

See foreach. —Bkell (talk) 15:24, 10 December 2010 (UTC)[reply]
See also map (higher-order function) and the even more powerful fold (higher-order function), which are features of functional languages. In most cases, those functions are even more direct than foreach-style loops. ("foreach" is just a "map" that doesn't return anything, so you have to usher the information out of the loop by assignment statements. The equivalent "map" can be much shorter.) Paul (Stansifer) 15:53, 10 December 2010 (UTC)[reply]
See also also list comprehension and array programming. --Tardis (talk) 18:40, 10 December 2010 (UTC)[reply]
If you are using a language that lets you work with memory directly, such as memcpy in C++, you can do this. For example, mempcy takes a destination, source, and number of copies to make. So, you could memcpy with j being the destination, k(y) being the source, and x being the number of copies to make. (and I think I should note that I do not believe this is an intended use for memcpy - it is more of a hack of how it works) -- kainaw 18:56, 10 December 2010 (UTC)[reply]
memcpymemset(3) will only work if your element size is a byte. C++ has the more general fill() and fill_n(). --Tardis (talk) 03:01, 11 December 2010 (UTC)[reply]
Are both of you are talking about memset, rather than memcpy? memcpy makes just one copy of the source; the third parameter is the size of the source. It works with any POD type, not just byte-sized types. memset can be used to zero out arrays of integers, but not to fill them with arbitrary values. -- BenRG (talk) 06:20, 11 December 2010 (UTC)[reply]
Yes, sorry: I deduced that Kainaw must have meant memset because it's filling the arbitrary-sized j(1:x) from the fixed size k(y). Then I proceeded to repeat his apparent mistake in my discussion of it. --Tardis (talk) 16:21, 11 December 2010 (UTC)[reply]
Another example of a high-level language with this functionality: in php you can do something like:
$my_array = array();
array_pad($my_array, $x, $k[$y]);
Then, my_array will be filled out to size x, all with value k[y]. -- kainaw 19:02, 10 December 2010 (UTC)[reply]
Assuming you want to replace all elements of the array, preserving the size, in Perl you can say @j = ($k[$y]) x @j;. In Python you can say j[:] = [k[y]] * len(j). In C++ you can say fill(j.begin(), j.end(), k[y]); or j.assign(j.size(), k[y]);. In Haskell you can say amap (const (k!y)) j. -- BenRG (talk) 06:20, 11 December 2010 (UTC)[reply]

Twitter

[edit]

Someone has, for example, 20,000 "tweets". How do you view them in chronological order from oldest to newest? There's only a "more" link at the bottom of the page which loads 10 more messages each time you click it. 82.44.55.25 (talk) 17:11, 10 December 2010 (UTC)[reply]

Hi, when I'm using the most recent twitter interface in Firefox, there is no "more" button, just a continuous scroll down through a twitterers tweets. It does however go from most recent through to oldest, rather than the chronological flow that you asked about. Technically, I suppose that you could scroll the whole way down to the first tweet, and then start scrolling back up, reading chronologically from oldest to newest. I've run searches on a number of terms to try to find a tool that might list tweets as you requested, but wasn't successful, I also tried to run google searches on twitter accounts to see if google might be able to do it (a bit like a google news search where you can arrange the results by date) but this too was unsuccessful. My suggestion to go all the way to a users first tweet and then navigate through the timelie from there is the only option that I can see at this moment in time. Darigan (talk) 17:20, 16 December 2010 (UTC)[reply]

Can setjmp(3) evaluate its argument more than once?

[edit]

The standard says that it's a macro, and in some implementations its argument is evaluated more than once. Is that a bug in that implementation (perhaps fixed since 2005), or is that allowed behavior? I don't see anything in the standard to forbid it, but it's obviously less useful if so (for the reasons mentioned in that mailing list post) and the standard doesn't specifically allow it either (like it does for putc()). --Tardis (talk) 18:48, 10 December 2010 (UTC)[reply]

Here they say:
Each of the following statements shall apply unless explicitly stated otherwise in the detailed descriptions that follow: ... Any invocation of a function that is implemented as a macro shall expand to code that evaluates each of its arguments exactly once, fully protected by parentheses where necessary, so it is generally safe to use arbitrary expressions as arguments.
Since the only places they explicitly warn about multiple evaluations are in putc() and friends, I think it's a bug for an implementation to do so with setjmp(). That doesn't mean it doesn't happen, of course. --Sean 20:47, 10 December 2010 (UTC)[reply]
That's true; I knew that (if I thought about it), and it ought to be enough. Thanks. (One could quibble that setjmp() isn't a function at all, so it isn't a "function that is implemented as a macro".) I wonder how frequent the implementations that do repeatedly evaluate are? (The one I linked to was actually sigsetjmp()/siglongjmp(), but the same principle applies.) --Tardis (talk) 21:57, 10 December 2010 (UTC)[reply]
I think this clause doesn't apply to this case for the reason you just stated. It's talking about the general provision that any standard library function may optionally (for speed reasons) be shadowed by a macro. Those macros are required to be as function-like as possible. I don't think that requirement extends to things that are explicitly stated to be macros. -- BenRG (talk) 04:37, 11 December 2010 (UTC)[reply]

How to allow firefox to access the web

[edit]
Resolved

How do I allow firefox to access the web? Albacore (talk) 21:19, 10 December 2010 (UTC)[reply]

One possible answer is to select File->Work Offline (remove the tick this option). A substantially different answer is that you need to pay an ISP for an internet connection. What's the nature of the problem? 213.122.23.184 (talk) 22:08, 10 December 2010 (UTC)[reply]
Aye, some more info would be nice, since Firefox is, after all, a Web browser. I have a question, though: Do you have a firewall? If so, is it either (a) blocking all access to Firefox or (b) on lockdown? —Jeremy (v^_^v Hyper Combo K.O.!) 22:38, 10 December 2010 (UTC)[reply]
Firefox worked until it updated to a new version. Then, McAfee warned me that it was trying to connect to the internet, or something very similar. I chose "block" to block Firefox from connecting to the internet twice. Now, of course, Firefox won't load.
Based on that, I would imply that the firewall is blocking access to Firefox. Albacore (talk) 23:16, 10 December 2010 (UTC)[reply]
I'm not familiar with McAfee, but somewhere (perhaps an expert can tell you where), you will find a list of blocked software, and you just need to remove Firefox from that list. Dbfirs 00:55, 12 December 2010 (UTC)[reply]

Quick to learn languages

[edit]

The Short Introduction To ABC, linked from ABC (programming language) says that it can be learnt in "an hour or so or so for someone who has already programmed". Are there any other languages that could also be learnt in an hour or so? Thanks. 92.24.190.135 (talk) 22:47, 10 December 2010 (UTC)[reply]

Depends what you mean by learned. Brainfuck can be learned very rapidly - a few minutes to get the way it works. But whether you would be a competent programmer in that or any other language after an hour is a different matter. Usually the simpler the syntax and the fewer the languages options the quicker to learn and the longer to be competent at using it. -- SGBailey (talk) 23:27, 10 December 2010 (UTC)[reply]
Yeah, I don't consider learning something in an hour to be a very good sign generally. Chess can be learned in less than an hour, but that doesn't mean you'll be any good at it. --Mr.98 (talk) 00:05, 11 December 2010 (UTC)[reply]
I would think BASIC could be learned in an hour by somebody familiar with programming, and maybe Pascal (programming language) as well. Looie496 (talk) 02:58, 11 December 2010 (UTC)[reply]

Would not Logo (programming language) and others aimed at children in the List of educational programming languages be learnable by adults with some experience of programming, within an hour or so? Micro-SiMPLE with four commands could be learnt in a few minutes. 92.28.246.75 (talk) 13:21, 12 December 2010 (UTC)[reply]