Search Results

Search found 916 results on 37 pages for 'stdio'.

Page 4/37 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Compiling Objective-C project on Linux (Ubuntu)

    - by Alex
    How to make an Objective-C project work on Ubuntu? My files are: Fraction.h #import <Foundation/NSObject.h> @interface Fraction: NSObject { int numerator; int denominator; } -(void) print; -(void) setNumerator: (int) n; -(void) setDenominator: (int) d; -(int) numerator; -(int) denominator; @end Fraction.m #import "Fraction.h" #import <stdio.h> @implementation Fraction -(void) print { printf( "%i/%i", numerator, denominator ); } -(void) setNumerator: (int) n { numerator = n; } -(void) setDenominator: (int) d { denominator = d; } -(int) denominator { return denominator; } -(int) numerator { return numerator; } @end main.m #import <stdio.h> #import "Fraction.h" int main( int argc, const char *argv[] ) { // create a new instance Fraction *frac = [[Fraction alloc] init]; // set the values [frac setNumerator: 1]; [frac setDenominator: 3]; // print it printf( "The fraction is: " ); [frac print]; printf( "\n" ); // free memory [frac release]; return 0; } I've tried two approaches to compile it: Pure gcc: $ sudo apt-get install gobjc gnustep gnustep-devel $ gcc `gnustep-config --objc-flags` -o main main.m -lobjc -lgnustep-base /tmp/ccIQKhfH.o:(.data.rel+0x0): undefined reference to `__objc_class_name_Fraction' I created a GNUmakefile Makefile: include ${GNUSTEP_MAKEFILES}/common.make TOOL_NAME = main main_OBJC_FILES = main.m include ${GNUSTEP_MAKEFILES}/tool.make ... and ran: $ source /usr/share/GNUstep/Makefiles/GNUstep.sh $ make Making all for tool main... Linking tool main ... ./obj/main.o:(.data.rel+0x0): undefined reference to `__objc_class_name_Fraction' So in both cases compiler gets stuck at undefined reference to `__objc_class_name_Fraction' Do you have and idea how to resolve this issue?

    Read the article

  • C headers: compiler specific vs library specific?

    - by leonbloy
    Is there some clear-cut distinction between standard C *.h header files that are provided by the C compiler, as oppossed to those which are provided by a standard C library? Is there some list, or some standard locations? Motivation: int this answer I got a while ago, regarding a missing unistd.h in the latest TinyC compiler, the author argued that unistd.h (contrarily to sys/unistd.h) should not be provided by the compiler but by your C library. I could not make much sense of that response (for one thing shouldn't that also apply to, say, stdio.h?) but I'm still wondering about it. Is that correct? Where is some authoritative reference for this? Looking in other compilers, I see that other "self contained" POSIX C compilers that are hosted in Windows (like the GCC toolchain that comes with MinGW, in several incarnations; or Digital Mars compiler), include all header files. And in a standard Linux distribution (say, Centos 5.10) I see that the gcc package provides a few header files (eg, stdbool.h, syslimits.h) in /usr/lib/gcc/i386-redhat-linux/4.1.1/include/, and the glibc-headers package provides the majority of the headers in /usr/include/ (including stdio.h, /usr/include/unistd.h and /usr/include/sys/unistd.h). So, in neither case I see support for the above claim.

    Read the article

  • Basic C programming question

    - by Amit
    Hi all, I've just started to learn C and it's going pretty slow...I wanted to write a program that takes in an integer argument and returns it's doubled value (aka take in integer, multiply by 2, and printf that value). I purposely did not want to use the scanf function. Here's what I have so far and what is not compiling... #include <stdio.h> int main(int index) { if (!(index)) { printf("No index given"); return 1; } a = index*2; printf("Mult by 2 %d",a); return 0; } So basically when the program is executed I want to supply the index integer. So, in cygwin, I would write something like ./a 10 and 10 would be stored into the index variable. Also, I want to program to return "No index given" and exit if no index value was supplied... Anyone care to help what I'm doing wrong? EDIT: This code returns 1 error upon compilation and is based on the help by @James: #include <stdio.h> int main(int 1, char index) { int index, a; if (!(index)) { printf("No index given"); return 1; } a = index*2; printf("Mult by 2 %d",a); return 0; } Thanks! Amit

    Read the article

  • Invoking a function (main()) from a binary file in C

    - by Dhara Darji
    I have simple c program like, my_bin.c: #include <stdio.h> int main() { printf("Success!\n"); return 0; } I compile it with gcc and got executable: my_bin. Now I want to invoke main (or run this my_bin) using another C program. That I did with mmap and function pointer like this: #include <stdio.h> #include <fcntl.h> #include <sys/mman.h> int main() { void (*fun)(); int fd; int *map; fd = open("./my_bin", O_RDONLY); map = mmap(0, 8378, PROT_READ, MAP_SHARED, fd, 0); fun = map; fun(); return 0; } PS: I went through some tutorial, for how to read binary file and execute. But this gives Seg fault, any help appreciated! Thanks!

    Read the article

  • Prime Numbers in C?

    - by Ali Azam Rana
    FIRST PROGRAM #include<stdio.h> void main() { int n,c; printf("enter a numb"); scanf("%i",n); for(c=2;c<=n;c++) { if(n%c==0) break; } if(c==n) printf("\nprime\n"); else printf("\nnot prime\n"); getchar(); } SECOND PROGRAM #include <stdio.h> int main() { printf("Enter a Number\n"); int in,loop,rem,chk; scanf("%d",&in); for (loop = 1; loop <=in; loop++) { rem = in % loop; if(rem == 0) chk = chk +1; } if (chk == 2) printf("\nPRIME NUM ENTERED\n"); else printf("\nNUM ENTERED NOT PRIME\n"); getchar(); } the 2nd program works other was the one my friend wrote the program looks fine but on checking it by stepping into we found that the if condition in first program is coming true under every input so whats the logical error here please help me found out......

    Read the article

  • Concise description of how .h and .m files interact in objective c?

    - by RJ86
    I have just started learning objective C and am really confused how the .h and .m files interact with each other. This simple program has 3 files: Fraction.h #import <Foundation/NSObject.h> @interface Fraction : NSObject { int numerator; int denominator; } - (void) print; - (void) setNumerator: (int) n; - (void) setDenominator: (int) d; - (int) numerator; - (int) denominator; @end Fraction.m #import "Fraction.h" #import <stdio.h> @implementation Fraction -(void) print { printf( "%i/%i", numerator, denominator ); } -(void) setNumerator: (int) n { numerator = n; } -(void) setDenominator: (int) d { denominator = d; } -(int) denominator { return denominator; } -(int) numerator { return numerator; } @end Main.m #import <stdio.h> #import "Fraction.h" int main(int argc, char *argv[]) { Fraction *frac = [[Fraction alloc] init]; [frac setNumerator: 1]; [frac setDenominator: 3]; printf( "The fraction is: " ); [frac print]; printf( "\n" ); [frac release]; return 0; } From what I understand, the program initially starts running the main.m file. I understand the basic C concepts but this whole "class" and "instance" stuff is really confusing. In the Fraction.h file the @interface is defining numerator and denominator as an integer, but what else is it doing below with the (void)? and what is the purpose of re-defining below? I am also quite confused as to what is happening with the (void) and (int) portions of the Fraction.m and how all of this is brought together in the main.m file. I guess what I am trying to say is that this seems like a fairly easy program to learn how the different portions work with each other - could anyone explain in non-tech jargon?

    Read the article

  • why malloc+memset slower than calloc?

    - by kingkai
    It's known that calloc differentiates itself with malloc in which it initializes the memory alloted. With calloc, the memory is set to zero. With malloc, the memory is not cleared. So in everyday work, i regard calloc as malloc+memset. Incidentally, for fun, i wrote the following codes for benchmark. The result is confused. Code 1: #include<stdio.h> #include<stdlib.h> #define BLOCK_SIZE 1024*1024*256 int main() { int i=0; char *buf[10]; while(i<10) { buf[i] = (char*)calloc(1,BLOCK_SIZE); i++; } } time ./a.out real 0m0.287s user 0m0.095s sys 0m0.192s Code 2: #include<stdio.h> #include<stdlib.h> #include<string.h> #define BLOCK_SIZE 1024*1024*256 int main() { int i=0; char *buf[10]; while(i<10) { buf[i] = (char*)malloc(BLOCK_SIZE); memset(buf[i],'\0',BLOCK_SIZE); i++; } } time ./a.out real 0m2.693s user 0m0.973s sys 0m1.721s Repalce memset with bzero(buf[i],BLOCK_SIZE) in Code 2 produce the result alike. My Question is that why malloc+memset is so much slower than calloc? How can calloc do that ? Thanks!

    Read the article

  • Goldbach theory in C

    - by nofe
    I want to write some code which takes any positive, even number (greater than 2) and gives me the smallest pair of primes that sum up to this number. I need this program to handle any integer up to 9 digits long. My aim is to make something that looks like this: Please enter a positive even integer ( greater than 2 ) : 10 The first primes adding : 3+7=10. Please enter a positive even integer ( greater than 2 ) : 160 The first primes adding : 3+157=160. Please enter a positive even integer ( greater than 2 ) : 18456 The first primes adding : 5+18451=18456. I don't want to use any library besides stdio.h. I don't want to use arrays, strings, or anything besides for the most basic toolbox: scanf, printf, for, while, do-while, if, else if, break, continue, and the basic operators (<,, ==, =+, !=, %, *, /, etc...). Please no other functions especially is_prime. I know how to limit the input to my needs so that it loops until given a valid entry. So now I'm trying to figure out the algorithm. I thought of starting a while loop like something like this: #include <stdio.h> long first, second, sum, goldbach, min; long a,b,i,k; //indices int main (){ while (1){ printf("Please enter a positive integer :\n"); scanf("%ld",&goldbach); if ((goldbach>2)&&((goldbach%2)==0)) break; else printf("Wrong input, "); } while (sum!=goldbach){ for (a=3;a<goldbach;a=(a+2)) for (i=2;(goldbach-a)%i;i++) first = a; for (b=5;b<goldbach;b=(b+2)) for (k=2;(goldbach-b)%k;k++) sum = first + second; } }

    Read the article

  • Need some help understanding a weird C behavior

    - by mike
    This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] = "abc"; int i, j; int count = 5; for((i=0) && (j=0); count > 0; i++ && j++){ printf("i = %d and j = %d\n", i, j); count--; } return 0; } The output as expected: i : 0 and j : 0 i : 1 and j : 1 i : 2 and j : 2 i : 3 and j : 3 i : 4 and j : 4 Things get weird when I uncomment the char string declaration on the first line of the function body. #include <stdio.h> int main(){ char somestring[3] = "abc"; ... } The output: i : 0 and j : 4195392 i : 1 and j : 4195393 i : 2 and j : 4195394 i : 3 and j : 4195395 i : 4 and j : 4195396 What's the logic behind this? I'm using gcc 4.4.1 on Ubuntu 9.10.

    Read the article

  • Receiving "expected expression before" Error When Using A Struct

    - by Zach Dziura
    I'm in the process of creating a simple 2D game engine in C with a group of friends at school. I'd like to write this engine in an Object-Oriented way, using structs as classes, function pointers as methods, etc. To emulate standard OOP syntax, I created a create() function which allocates space in memory for the object. I'm in the process of testing it out, and I'm receiving an error. Here is my code for two files that I'm using to test: test.c: #include <stdio.h> int main() { typedef struct { int i; } Class; Class *test = (Class*) create(Class); test->i = 1; printf("The value of \"test\" is: %i\n", test->i); return 0; } utils.c: #include <stdio.h> #include <stdlib.h> #include "utils.h" void* create(const void* class) { void *obj = (void*) malloc(sizeof(class)); if (obj == 0) { printf("Error allocating memory.\n"); return (int*) -1; } else { return obj; } } void destroy(void* object) { free(object); } The utils.h file simply holds prototypes for the create() and destroy() functions. When I execute gcc test.c utils.c -o test, I'm receiving this error message: test.c: In function 'main': test.c:10:32: error: expected expression before 'Class' I know it has something to do with my typedef at the beginning, and how I'm probably not using proper syntax. But I have no idea what that proper syntax is. Can anyone help?

    Read the article

  • Deprecated functions not spotted if using "System::Threading::ThreadState" (and others!) C++ VS2005/

    - by Fishboy
    Hi, I'm facing an issue with c++ on vs2005 and also vs2008... here's how you can reproduce the issue.... create a new (c++) project called 'test' (file|new|project) select "Windows Forms Application" and add the 'stdio.h' include and the code fragment below into the test.cpp source file..... -------------------start of snippet-------------------- #include <stdio.h> ... int main(array<System::String ^> ^args) { int i; System::Threading::ThreadState state; char str[20]; sprintf (str, "%s", "test string"); ... -------------------end of snippet-------------------- If you compile the code as above (you'll have to 'buildall' first), you'll get two warnings about 'i' and 'state' being unreferenced (nothing about sprintf being deprecated). If you comment out "System::Threading :Thread state;", you'll get one warning about 'i' being unreferenced and another warning (C4996) for the 'deprecated' sprintf statement.... This issue also occurs for "System::Windows::Forms::MessageBoxIcon", "System::Base64FormattingOptions" (and perhap all 'enum class' types!) Anyone know of the cause and workaround to the issue demonstrated here ( i have other files that demonstate this issue..). (I had started a thread on msdn, but then found this site! see link below) Visual Studio 2005 has stopped warning about deprecated functions

    Read the article

  • Function pointers uasage

    - by chaitanyavarma
    Hi All, Why these two codes give the same output, Case - 1: #include <stdio.h> typedef void (*mycall) (int a ,int b); void addme(int a,int b); void mulme(int a,int b); void subme(int a,int b); main() { mycall x[10]; x[0] = &addme; x[1] = &subme; x[2] = &mulme; (x[0])(5,2); (x[1])(5,2); (x[2])(5,2); } void addme(int a, int b) { printf("the value is %d\n",(a+b)); } void mulme(int a, int b) { printf("the value is %d\n",(a*b)); } void subme(int a, int b) { printf("the value is %d\n",(a-b)); } Output: the value is 7 the value is 3 the value is 10 Case -2 : #include <stdio.h> typedef void (*mycall) (int a ,int b); void addme(int a,int b); void mulme(int a,int b); void subme(int a,int b); main() { mycall x[10]; x[0] = &addme; x[1] = &subme; x[2] = &mulme; (*x[0])(5,2); (*x[1])(5,2); (*x[2])(5,2); } void addme(int a, int b) { printf("the value is %d\n",(a+b)); } void mulme(int a, int b) { printf("the value is %d\n",(a*b)); } void subme(int a, int b) { printf("the value is %d\n",(a-b)); } Output: the value is 7 the value is 3 the value is 10

    Read the article

  • Function pointers usage

    - by chaitanyavarma
    Hi All, Why these two codes give the same output, Case 1: #include <stdio.h> typedef void (*mycall) (int a ,int b); void addme(int a,int b); void mulme(int a,int b); void subme(int a,int b); main() { mycall x[10]; x[0] = &addme; x[1] = &subme; x[2] = &mulme; (x[0])(5,2); (x[1])(5,2); (x[2])(5,2); } void addme(int a, int b) { printf("the value is %d\n",(a+b)); } void mulme(int a, int b) { printf("the value is %d\n",(a*b)); } void subme(int a, int b) { printf("the value is %d\n",(a-b)); } Output: the value is 7 the value is 3 the value is 10 Case 2 : #include <stdio.h> typedef void (*mycall) (int a ,int b); void addme(int a,int b); void mulme(int a,int b); void subme(int a,int b); main() { mycall x[10]; x[0] = &addme; x[1] = &subme; x[2] = &mulme; (*x[0])(5,2); (*x[1])(5,2); (*x[2])(5,2); } void addme(int a, int b) { printf("the value is %d\n",(a+b)); } void mulme(int a, int b) { printf("the value is %d\n",(a*b)); } void subme(int a, int b) { printf("the value is %d\n",(a-b)); } Output: the value is 7 the value is 3 the value is 10

    Read the article

  • Why does the order of the loops affect performance when iterating over a 2D array? [closed]

    - by Mark
    Possible Duplicate: Which of these two for loops is more efficient in terms of time and cache performance Below are two programs that are almost identical except that I switched the i and j variables around. They both run in different amounts of time. Could someone explain why this happens? Version 1 #include <stdio.h> #include <stdlib.h> main () { int i,j; static int x[4000][4000]; for (i = 0; i < 4000; i++) { for (j = 0; j < 4000; j++) { x[j][i] = i + j; } } } Version 2 #include <stdio.h> #include <stdlib.h> main () { int i,j; static int x[4000][4000]; for (j = 0; j < 4000; j++) { for (i = 0; i < 4000; i++) { x[j][i] = i + j; } } }

    Read the article

  • 'table' undeclared (first use this in a function)

    - by user2318083
    So I'm not sure why this isn't working, I'm creating a new table and setting it to the variable 'table' Is there something I'm doing wrong? This is the error I get when trying to run it: src/simpleshell.c:19:3: error: ‘table’ undeclared (first use in this function) src/simpleshell.c:19:3: note: each undeclared identifier is reported only once for each function it appears in My code is as follows: #include "parser.h" #include "hash_table.h" #include "variables.h" #include "shell.h" #include <stdio.h> int main(void) { char input[MAXINPUTLINE]; table = Table_create(); signal_c_init(); printf("\nhlsh$ "); while(fgets(input, sizeof(input), stdin)){ stripcrlf(input); parse(input); printf("\nhlsh$ "); } Table_free(table); return 0; } Then this is my create a table in the hash_table file: struct Table *Table_create(void){ struct Table *t; t = (struct Table*)calloc(1, sizeof(struct Table)); return t; } From the hash_table.c: #include "hash_table.h" #include "parser.h" #include "shell.h" #include "variables.h" #include <stdio.h> #include <sys/resource.h> #include <sys/wait.h> #include <sys/types.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <pwd.h> #include <fcntl.h> #include <limits.h> #include <signal.h> struct Table *table; unsigned int hash(const char *x){ int i; unsigned int h = 0U; for (i=0; x[i]!='\0'; i++){ h = h * 65599 + (unsigned char)x[i]; } return h % 1024; }

    Read the article

  • Make fails compiling GCC

    - by TheGatorade
    I'm trying to Linux From Scratch, I'm compiling GCC. I get this error: In file included from /usr/include/stdio.h:28:0, from ../.././gcc-4.7.0/libgcc/../gcc/tsystem.h:88, from ../.././gcc-4.7.0/libgcc/libgcc2.c:29: /usr/include/features.h:324:26: fatal error: bits/predefs.h: No such file or directory compilation terminated. I don't know how to fix this. I'm using GCC version 4.7.0 Anyone knows how to fix this?

    Read the article

  • Getting time in ubuntu

    - by user2578666
    include #include <stdio.h> int GetTime() { struct timespec tsp; clock_gettime(CLOCK_REALTIME, &tsp); //Call clock_gettime to fill tsp fprintf(stdout, "time=%d.%d\n", tsp.tv_sec, tsp.tv_nsec); fflush(stdout); } I am trying to compile the above code but it keeps throwing the error: time.c: In function ‘GetTime’: time.c:12:4: warning: implicit declaration of function ‘clock_gettime’ [-Wimplicit-function-declaration] time.c:12:18: error: ‘CLOCK_REALTIME’ undeclared (first use in this function) time.c:12:18: note: each undeclared identifier is reported only once for each function it appears in time.c:14:4: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘__time_t’ [-Wformat] time.c:14:4: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long int’ [-Wformat] I have tried compiling with -lrt flag and -std=gnu99. Nothing works.

    Read the article

  • In C what is the difference between null and a new line character? Guys help please [migrated]

    - by Siddhartha Gurjala
    Whats the conceptual difference and similarity between NULL and a newline character i.e between '\0' and '\n' Explain their relevance for both integer and character data type variables and arrays? For reference here is an example snippets of a program to read and write a 2d char array PROGRAM CODE 1: int main() { char sort(),stuname(),swap(),(*p)(),(*q)(); int n; p=stuname; q=swap; printf("Let the number of students in the class be \n"); scanf("%d",&n); fflush(stdin); sort(p,q,n); return 0; } char sort(p1,q1,n1) char (*p1)(),(*q1)(); int n1; { (*p1)(n1); (*q1)(); } char stuname(int nos) // number of students { char name[nos][256]; int i,j; printf("Reading names of %d students started--->\n\n",nos); name[0][0]='k'; //initialising as non NULL charecter for(i=0;i<nos;i++) // nos=number of students { printf("Give name of student %d\n",i); for(j=0;j<256;j++) { scanf("%c",&name[i][j]); if(name[i][j]=='\n') { name[i][j]='\0'; j=257; } } } printf("\n\nWriting student names:\n\n"); for(i=0;i<nos;i++) { for(j=0;j<256&&name[i][j]!='\0';j++) { printf("%c",name[i][j]); } printf("\n"); } } char swap() { printf("Will swap shortly after getting clarity on scanf and %c"); } The above code is working good where as the same logic given with slight diff is not giving appropriate output. Here's the code PROGRAM CODE 2: #include<stdio.h> int main() { char sort(),stuname(),swap(),(*p)(),(*q)(); int n; p=stuname; q=swap; printf("Let the number of students in the class be \n"); scanf("%d",&n); fflush(stdin); sort(p,q,n); return 0; } char sort(p1,q1,n1) char (*p1)(),(*q1)(); int n1; { (*p1)(n1); (*q1)(); } char stuname(int nos) // number of students { char name[nos][256]; int i,j; printf("Reading names of %d students started--->\n\n",nos); name[0][0]='k'; //initialising as non NULL charecter for(i=0;i<nos;i++) // nos=number of students { printf("Give name of student %d\n",i); ***for(j=0;j<256&&name[i][j]!='\0';j++)*** { scanf("%c",&name[i][j]); /*if(name[i][j]=='\n') { name[i][j]='\0'; j=257; }*/ } } printf("\n\nWriting student names:\n\n"); for(i=0;i<nos;i++) { for(j=0;j<256&&name[i][j]!='\0';j++) { printf("%c",name[i][j]); } printf("\n"); } } char swap() { printf("Will swap shortly after getting clarity on scanf and %c"); } Here one more instance of same program not giving proper output given below PROGRAM CODE 3: #include<stdio.h> int main() { char sort(),stuname(),swap(),(*p)(),(*q)(); int n; p=stuname; q=swap; printf("Let the number of students in the class be \n"); scanf("%d",&n); fflush(stdin); sort(p,q,n); return 0; } char sort(p1,q1,n1) char (*p1)(),(*q1)(); int n1; { (*p1)(n1); (*q1)(); } char stuname(int nos) // number of students { char name[nos][256]; int i,j; printf("Reading names of %d students started--->\n\n",nos); name[0][0]='k'; //initialising as non NULL charecter for(i=0;i<nos;i++) // nos=number of students { printf("Give name of student %d\n",i); ***for(j=0;j<256&&name[i][j]!='\n';j++)*** { scanf("%c",&name[i][j]); /*if(name[i][j]=='\n') { name[i][j]='\0'; j=257; }*/ } name[i][i]='\0'; } printf("\n\nWriting student names:\n\n"); for(i=0;i<nos;i++) { for(j=0;j<256&&name[i][j]!='\0';j++) { printf("%c",name[i][j]); } printf("\n"); } } char swap() { printf("Will swap shortly after getting clarity on scanf and %c"); } Why the program code 2 and program code 3 are not working as expected as that of the code 1?

    Read the article

  • What is this code?

    - by Aerovistae
    This is from the Evolution of a Programmer "joke", at the "Master Programmer" level. It seems to be C++, but I don't know what all this bloated extra stuff is, nor did any Google searches turn up anything except the joke I took it from. Can anyone tell me more about what I'm reading here? [ uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820) ] library LHello { // bring in the master library importlib("actimp.tlb"); importlib("actexp.tlb"); // bring in my interfaces #include "pshlo.idl" [ uuid(2573F8F5-CFEE-101A-9A9F-00AA00342820) ] cotype THello { interface IHello; interface IPersistFile; }; }; [ exe, uuid(2573F890-CFEE-101A-9A9F-00AA00342820) ] module CHelloLib { // some code related header files importheader(<windows.h>); importheader(<ole2.h>); importheader(<except.hxx>); importheader("pshlo.h"); importheader("shlo.hxx"); importheader("mycls.hxx"); // needed typelibs importlib("actimp.tlb"); importlib("actexp.tlb"); importlib("thlo.tlb"); [ uuid(2573F891-CFEE-101A-9A9F-00AA00342820), aggregatable ] coclass CHello { cotype THello; }; }; #include "ipfix.hxx" extern HANDLE hEvent; class CHello : public CHelloBase { public: IPFIX(CLSID_CHello); CHello(IUnknown *pUnk); ~CHello(); HRESULT __stdcall PrintSz(LPWSTR pwszString); private: static int cObjRef; }; #include <windows.h> #include <ole2.h> #include <stdio.h> #include <stdlib.h> #include "thlo.h" #include "pshlo.h" #include "shlo.hxx" #include "mycls.hxx" int CHello:cObjRef = 0; CHello::CHello(IUnknown *pUnk) : CHelloBase(pUnk) { cObjRef++; return; } HRESULT __stdcall CHello::PrintSz(LPWSTR pwszString) { printf("%ws\n", pwszString); return(ResultFromScode(S_OK)); } CHello::~CHello(void) { // when the object count goes to zero, stop the server cObjRef--; if( cObjRef == 0 ) PulseEvent(hEvent); return; } #include <windows.h> #include <ole2.h> #include "pshlo.h" #include "shlo.hxx" #include "mycls.hxx" HANDLE hEvent; int _cdecl main( int argc, char * argv[] ) { ULONG ulRef; DWORD dwRegistration; CHelloCF *pCF = new CHelloCF(); hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); // Initialize the OLE libraries CoInitiali, NULL); // Initialize the OLE libraries CoInitializeEx(NULL, COINIT_MULTITHREADED); CoRegisterClassObject(CLSID_CHello, pCF, CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &dwRegistration); // wait on an event to stop WaitForSingleObject(hEvent, INFINITE); // revoke and release the class object CoRevokeClassObject(dwRegistration); ulRef = pCF->Release(); // Tell OLE we are going away. CoUninitialize(); return(0); } extern CLSID CLSID_CHello; extern UUID LIBID_CHelloLib; CLSID CLSID_CHello = { /* 2573F891-CFEE-101A-9A9F-00AA00342820 */ 0x2573F891, 0xCFEE, 0x101A, { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 } }; UUID LIBID_CHelloLib = { /* 2573F890-CFEE-101A-9A9F-00AA00342820 */ 0x2573F890, 0xCFEE, 0x101A, { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 } }; #include <windows.h> #include <ole2.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include "pshlo.h" #include "shlo.hxx" #include "clsid.h" int _cdecl main( int argc, char * argv[] ) { HRESULT hRslt; IHello *pHello; ULONG ulCnt; IMoniker * pmk; WCHAR wcsT[_MAX_PATH]; WCHAR wcsPath[2 * _MAX_PATH]; // get object path wcsPath[0] = '\0'; wcsT[0] = '\0'; if( argc > 1) { mbstowcs(wcsPath, argv[1], strlen(argv[1]) + 1); wcsupr(wcsPath); } else { fprintf(stderr, "Object path must be specified\n"); return(1); } // get print string if(argc > 2) mbstowcs(wcsT, argv[2], strlen(argv[2]) + 1); else wcscpy(wcsT, L"Hello World"); printf("Linking to object %ws\n", wcsPath); printf("Text String %ws\n", wcsT); // Initialize the OLE libraries hRslt = CoInitializeEx(NULL, COINIT_MULTITHREADED); if(SUCCEEDED(hRslt)) { hRslt = CreateFileMoniker(wcsPath, &pmk); if(SUCCEEDED(hRslt)) hRslt = BindMoniker(pmk, 0, IID_IHello, (void **)&pHello); if(SUCCEEDED(hRslt)) { // print a string out pHello->PrintSz(wcsT); Sleep(2000); ulCnt = pHello->Release(); } else printf("Failure to connect, status: %lx", hRslt); // Tell OLE we are going away. CoUninitialize(); } return(0); }

    Read the article

  • C Problem with Compiler?

    - by Solomon081
    I just started learning C, and wrote my hello world program: #include <stdio.h> main() { printf("Hello World"); return 0; } When I run the code, I get a really long error: Apple Mach-O Linker (id) Error Ld /Users/Solomon/Library/Developer/Xcode/DerivedData/CProj-cwosspupvengheeaapmkrhxbxjvk/Build/Products/Debug/CProj normal x86_64 cd /Users/Solomon/Desktop/C/CProj setenv MACOSX_DEPLOYMENT_TARGET 10.7 /Developer/usr/bin/clang -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -L/Users/Solomon/Library/Developer/Xcode/DerivedData/CProj-cwosspupvengheeaapmkrhxbxjvk/Build/Products/Debug -F/Users/Solomon/Library/Developer/Xcode/DerivedData/CProj-cwosspupvengheeaapmkrhxbxjvk/Build/Products/Debug -filelist /Users/Solomon/Library/Developer/Xcode/DerivedData/CProj-cwosspupvengheeaapmkrhxbxjvk/Build/Intermediates/CProj.build/Debug/CProj.build/Objects-normal/x86_64/CProj.LinkFileList -mmacosx-version-min=10.7 -o /Users/Solomon/Library/Developer/Xcode/DerivedData/CProj-cwosspupvengheeaapmkrhxbxjvk/Build/Products/Debug/CProj ld: duplicate symbol _main in /Users/Solomon/Library/Developer/Xcode/DerivedData/CProj-cwosspupvengheeaapmkrhxbxjvk/Build/Intermediates/CProj.build/Debug/CProj.build/Objects-normal/x86_64/helloworld.o and /Users/Solomon/Library/Developer/Xcode/DerivedData/CProj-cwosspupvengheeaapmkrhxbxjvk/Build/Intermediates/CProj.build/Debug/CProj.build/Objects-normal/x86_64/main.o for architecture x86_64 Command /Developer/usr/bin/clang failed with exit code 1 I am running xCode Should I reinstall DevTools?

    Read the article

  • C code - ls system command not showing bash colors

    - by m0atz
    I've just been fooling around with some code in C, an example of a really basic program is as follows which just, obviously, lists the directories using the ls system command. #include <stdio.h> int main (void) { system("ls -l -d */"); printf("I've just listed the directories :-)\n"); return 0; } This runs fine, but it shows the ls output in monochrome, whereas Bash would output the list using colors for the directories (or files if I included files). How can I make my C code use the bash colors? Thanks

    Read the article

  • Hide debug information when running apps from the command line

    - by tutuca
    Most of the time running a gtk application from the command line it starts dumping debug information to the stdio even though I put them in background. Example: ~$ gedit test.html # and ctrl+z to suspend zsh: suspended gedit .zshrc ~$ bg [1] + continued gedit .zshrc ~$ # do some editing (gedit:6208): GtkSourceView-WARNING **: Could not find word to remove in buffer (whoosh), this should not happen! (gedit:6208): GtkSourceView-WARNING **: Could not find word to remove in buffer (haystack), this should not happen! I want to note that the error, or warning, changes according to what I'm doing at the moment. The GtkSourceView-WARNING shown here is one of the cases. Anyway... Do you know if it's at all possible to avoid getting that information printed out?

    Read the article

  • how to generate number pattern in triangular form

    - by Vignesh Vicky
    I want to print this pattern like right angled triangle 0 909 89098 7890987 678909876 56789098765 4567890987654 345678909876543 23456789098765432 1234567890987654321 I wrote following code # include<stdio.h> # include<conio.h> void main() { clrscr(); int i,j,x,z,k,f=1; for ( i=10;i>=1;i--,f++) { for(j=1;j<=f;j++,k--) { k=i; if(k!=10) { printf("%d",k); } if(k==10) { printf("0"); } } for(x=1;x<f;x++,z--) { z=9; printf("%d",z); } printf("%d/n"); } getch(); } what is wrong with this code? when i check manually it seems correct but when compiled gives different pattern

    Read the article

  • What is the runtime of this program

    - by grebwerd
    I was wondering what the run time of this small program would be? #include <stdio.h> int main(int argc, char* argv[]) { int i; int j; int inputSize; int sum = 0; if(argc == 1) inputSize = 16; else inputSize = atoi(argv[i]); for(i = 1; i <= inputSize; i++){ for(j = i; j < inputSize; j *=2 ){ printf("The value of sum is %d\n",++sum); } } } n S floor(log n - log (n-i)) = ? i =1 and that each summation would be the floor value between log(n) - log(n-i). Would the run time be n log n?

    Read the article

  • What is the Big-O time complexity of this algorithm

    - by grebwerd
    I was wondering what the run time of this small program would be? #include <stdio.h> int main(int argc, char* argv[]) { int i; int j; int inputSize; int sum = 0; if(argc == 1) inputSize = 16; else inputSize = atoi(argv[i]); for(i = 1; i <= inputSize; i++){ for(j = i; j < inputSize; j *=2 ){ printf("The value of sum is %d\n",++sum); } } } n S floor(log n - log (n-i)) = ? i =1 and that each summation would be the floor value between log(n) - log(n-i). Would the run time be n log n?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >