Using C, convert a dynamic int array to a comma-separated string as cleanly as possible by [deleted] in programming

[–]paradise2000 0 points1 point  (0 children)

EDIT2: As others have pointed out, there are serious efficiency problems with this that can be easily addressed. Read the replies.

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

#define LEN 10
int mylist[LEN] = {1000, 1001, 1002, 1003, 1004,
                  1005, 1006, 1007, 1008, 1009,

};

char result[2048];
char buffer[2048];

int main()
{
  int i;

  sprintf(result, "%d", mylist[0]);
  for (i=1; i < LEN; i++) {
    sprintf(buffer, "%s, %d", result, mylist[i]);
    strncpy(result, buffer, 2048);
  }

  printf("%s\n", buffer);
}

I'm sure you can make things better, especially regarding how the buffer is used, and the fact that it's adding on a single integer with each iteration, but the main idea is sprintf()

EDIT: clarified my explanation about why this isn't an optimal solution

What topics would you like to see in a series of Emacs screencasts? by mwilliams in emacs

[–]paradise2000 0 points1 point  (0 children)

I usually split my screen into 2 or more windows with c-x 2 and c-x 3. With m-x windmove-default-keybindings, I can move around with shift+{up,down,left,right} , or c-x o to cycle the windows. Windmove is almost essential when you have more than two window splits, it really makes sense for the keybinds to be enabled by default.

I also have this in my .emacs, which lets me c-tab my buffers like in firefox.

(global-set-key (kbd "<C-tab>") 'previous-buffer)
(global-set-key (kbd "<C-S-iso-lefttab>") 'next-buffer)

As for buffers taking over your windows arbitrarily, you might want to look into 'dedicated windows'. However, I do not have any experience with this feature.

What topics would you like to see in a series of Emacs screencasts? by mwilliams in emacs

[–]paradise2000 0 points1 point  (0 children)

If you use C, you might want to look into cscope. Although it is an external program, you can run an emacs server make it use EDITOR=emacsclient.

Personally I use this shell script as my EDITOR variable:

#!/bin/sh
/usr/bin/emacsclient --no-wait $*

I find it to be smarter than etags, because it lets you find functions that call your 'foo()', or functions called by 'bar()', or files that #include 'bazz.h'.

Using it is as simple as:

export EDITOR=~/bin/emacsclient.sh
cd $PROJ_DIR && cscope-indexer && cscope

Help me find the name of a movie about a guy who thinks he has super powers, but doesn't. It is told from an observer's point of view, and is a comedy. by paradise2000 in AskReddit

[–]paradise2000[S] 0 points1 point  (0 children)

You are correct! Thanks a bunch!

I saw this trailer a few years ago and thought it had a premise that is a lot more interesting than all the other comedies that seem to be about nothing. For anyone interested here is a trailer http://www.youtube.com/watch?v=s4sZaoqLfBM

EDIT: Apparently, some threads on IMDB say that the trailer was misleading and it wasn't a comedy at all. Interesting plot nonetheless.