Search Results

Search found 6123 results on 245 pages for 'unsigned char'.

Page 45/245 | < Previous Page | 41 42 43 44 45 46 47 48 49 50 51 52  | Next Page >

  • Another dynamic memory allocation bug.

    - by m4design
    I'm trying to allocate memory for a multidimensional array (8 rows, 3 columns). Here's the code for the allocation (I'm sure the error is clear for you) char **ptr = (char **) malloc( sizeof(char) * 8); for (i = 0; i < 3; i++) ptr[i] = (char *) malloc( sizeof(char) * 3); The crash happens when I reference this: ptr[3][0]; Unhandled exception at 0x0135144d in xxxx.exe: 0xC0000005: Access violation writing location 0xabababab. Are there any recommended references/readings for this kind of subject? Thanks.

    Read the article

  • Poco C++ library on OSX 10.8.2: Undefined symbols for architecture x86_64

    - by Arman
    I'm trying to use Poco C++ library to do the simple http requests in C++ on Mac OS X 10.8.2. I installed Poco, copy-pasted the http_request.cc code from this tutorial, ran it with 'g++ -o http_get http_get.cc -lPocoNet', but got: Undefined symbols for architecture x86_64: "Poco::StreamCopier::copyStream(std::basic_istream<char, std::char_traits<char> >&, std::basic_ostream<char, std::char_traits<char> >&, unsigned long)", referenced from: _main in ccKuZb1g.o "Poco::URI::URI(char const*)", referenced from: _main in ccKuZb1g.o "Poco::URI::~URI()", referenced from: _main in ccKuZb1g.o "Poco::URI::getPathAndQuery() const", referenced from: _main in ccKuZb1g.o "Poco::URI::getPort() const", referenced from: _main in ccKuZb1g.o "Poco::Exception::displayText() const", referenced from: _main in ccKuZb1g.o "typeinfo for Poco::Exception", referenced from: GCC_except_table1 in ccKuZb1g.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status Have been struggling with this for couple of hours. Any idea how to fix this? Thanks in advance!

    Read the article

  • How to upload an image to imageshark using curl?

    - by cinek1lol
    Hello: I wrote a program using curl.exe that sends pictures to imageshark and receives a link to the pictures. The problem that I have to specify the path to the image on the disk, and the rest of my so constructed that I have uploaded these pictures to a binary char array And I mean, I can send these pictures to char variable, and not giving the file path (you know what I mean?) Not too much know how to use it to save the library directly to curl. I'll be very grateful for any help sorry I know little English. wants to send a file loaded POST method to the variable char binary. Programs that are written above, send the file to disk. Do you understand what's going on? This is look like I would like to send the file in char variable, rather than on the hard disk I found the program, but he sends the entire file, and I would like to have it sent to the variable char dz

    Read the article

  • C programing some errors :(

    - by Pedro
    Hi...this is a little code that i'm doing, but i have some errors...:S Hi have a txt file and i want to "convert to xml", but the program must know what is comments, and must organize... txt file: /* Licenciaturas na ESTG-IPVC 2009 – v1.1*/ - Info, <N Alunos> <hr>--------------------------------------------------- 3 <hr>--------------------------------------------------- - data, <course><Number>;<name>;<email> - disciplinas, <n disciplines>;<note>;[<note>;] </hr>--------------------------------------------------- LEI;7671;Name name name;[email protected]; 9;8;12;9;12;11;6;15;7;11; LTCGM;6567;nam1 nam2 nam3;[email protected]; 6;13;14;12;11;16;14; LEI;7701;xxxxx xxxx xxxx;[email protected]; 8;13;11;7;14;12;11;16;14; My code: int main(int argc, char *argv[]) { char first[60];//array char comment[60];//array char nome_int[60];//array char total[60];//array char course[60];//array int i; char notas[60]; char *number, *name, *mail, *total_disci; int total_cad; char disciplines[60]; printf("Int. the name of the file to convert\n"); scanf("%s",&nome_int); FILE *fp = fopen(nome_int, "r"); //open file FILE *conver = fopen("conver.xml","w");// opne output FILE *coment = fopen("coment.txt","w"); if (fp == NULL) { printf("File not found\n"); exit(1); } else { fgets(first, 60,fp); fputs(first,coment); while (!(feof(fp))){ fgets(first, 60, fp); if (first[0] == '-'){ fputs(first,coment); } for(i=1;fscanf(fp,"%s",total)!=-5;i++){ if(i==2){ printf("Total %s",total);//here the program stops } } fgets(course,60,fp); if(course[0]=='L'){ number = strchr(course, ';');//here course is an array but must be an appointer, what can i do? *number = '\0'; number++; name = strchr(number, ';'); *name = '\0'; name++; mail= strchr(name, ';'); *mail = '\0'; mail++; char *curso1; total_cad=atoi(total_disci); printf("Course: %s\n",course); printf("Number: %s\n",number); printf("Name: %s\n",name); printf("e-mail: %s\n",mail); } fgets(disciplines,60,fp);//here crash total_disci= strchr(mail, ';'); *total_disci = '\n'; total_disci++; printf("Total disciplines: %d\n",total_cad); } } fclose(fp); fclose(coment); fclose(conver); system("PAUSE"); return 0; } the convert file must be like this: <xml> <list_courses> <course> <sigla>LEI</sigla> <NAlunos>2</NAlunos> <list_students> <students> <number>7671</number> <name>name name name</name> <email>[email protected]</email> <stat>disaproved</stat> <media_notes>10</media_notes> <biggest_note>15</biggest_note> <small_nota>6</small_nota> </students> </list_students> </course> </list_courses> </xml> _______________________________________- now separated by only comment on what is what and converted to xml. also had to do was impressed that the program could name, email address, number, etc. .. here the main errors do not want to do for me, just want to see the errors, I spent the whole day right back from them and nothing ... someone who can help, please do it :)

    Read the article

  • string manipulations in C

    - by Vivek27
    Following are some basic questions that I have with respect to strings in C. If string literals are stored in read-only data segment and cannot be changed after initialisation, then what is the difference between the following two initialisations. char *string = "Hello world"; const char *string = "Hello world"; When we dynamically allocate memory for strings, I see the following allocation is capable enough to hold a string of arbitary length.Though this allocation work, I undersand/beleive that it is always good practice to allocate the actual size of actual string rather than the size of data type.Please guide on proper usage of dynamic allocation for strings. char *string = (char *)malloc(sizeof(char));

    Read the article

  • Very difficult SQL query

    - by db666
    For the following table definitions: Name Null? Type Comments ------------------------------- -------- ---- ------------------------------------ ENUM NOT NULL NUMBER(4) ENUM should not exceed a length of 4. ENAME CHAR(15) ADDRESS CHAR(25) ADDRESS should not exceed 25 characters. SALARY NUMBER(5) OFFICE CHAR(4) DNUM NOT NULL NUMBER(4) Department which this employee belongs to department Name Null? Type Comments ------------------------------- -------- ---- ------------------------------------- DNUM NOT NULL NUMBER(4) DMGR NOT NULL NUMBER(4) Department manager DNAME NOT NULL CHAR(15) project Name Null? Type Comments ------------------------------- -------- ---- ------------------------------------- PNUM NOT NULL NUMBER(4) PMGR NOT NULL NUMBER(4) Project manager PTITLE NOT NULL CHAR(15) emp_proj Name Null? Type ------------------------------- -------- ---- PNUM NOT NULL NUMBER(4) ENUM NOT NULL NUMBER(4) I have to write SQL query which will find the names of employees who do not share an office but work on the same project, and have different salaries... I've spent last three days trying to figure out something, but no idea as far. I will appreciate any advice.

    Read the article

  • Constructors for C++ objects

    - by sasquatch
    I have class Person as following : class Person { char* name; int age; }; Now I need to add two contructors. One taking no arguments, that inserts field values to dynamically allocated resources. Second taking (char*, int) arguments initialized by initialization list. Last part is to define a destructor showing information about destroying objects and deallocating dynamically allocated resources. How to perform this task ? That's what I already have : class Person { char* name; int age; public: Person(){ this->name = new *char; this->age = new int; } Person(char* c, int i){ } };

    Read the article

  • parsing Two-dimensional array in c

    - by gitter78
    I'm trying to parse an array that looks like the one below: char *arr[][2] = { { "1", "Purple" }, { "2", "Blue" }, { "22", "Red" }, ... }; I was thinking having a loop as: char *func(char *a){ for(i = 0; i<sizeof(arr)/sizeof(arr[0]);i++){ if(strstr(a,arr[i][0])!=NULL) return arr[i][1]; } } char *out; const char *hello = "this is my 2 string"; out = func(hello); In this case, I'm trying to get the second value based on the first one: Purple, Blue Red, etc.. The question is how would go in parsing this and instead of printing out the value, return the value. UPDATE/FIXED: It has been fixed above. Thanks

    Read the article

  • C string program

    - by mrblippy
    Hi, i have been given a task to do ar school that must read three strings in, store the third string in dynamically allocated memory and print out the last 4 letters of the first word alphabetically. Here is the program i have so far but the strings are all stored in different variables, making them hard to sort. if anyone could give me a hand and help me finish this program i would be very grateful. thanks #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char word1[101]; char word2[101]; char* word3; char buffer[101]; scanf("%s", word1); scanf("%s", word2); scanf("%s", buffer); word3 = (char *) malloc(strlen(buffer)+1); strcpy(word3, buffer); return 0; }

    Read the article

  • strtok program crashing.

    - by baskin
    Hi, the program for strtok given on http://www.opengroup.org/onlinepubs/000095399/functions/strtok.html crashes everytime.. #include <string.h> ... char *token; char *line = "LINE TO BE SEPARATED"; char *search = " "; /* Token will point to "LINE". */ token = strtok(line, search); /* Token will point to "TO". */ token = strtok(NULL, search); If I use a char array for variable 'line', it works. i.e. char line[] = "LINE TO BE SEPARATED" works. Kindly explain.

    Read the article

  • What does this C++ code mean

    - by Markus Orreilly
    I was trying to understand how webkit parses urls, and I'm having a hard time making heads or tails of this: Vector<char, 4096> buffer(fragmentEnd * 3 + 1); This line is on line 1214 (you can see it here: http://trac.webkit.org/browser/trunk/WebCore/platform/KURL.cpp#L1214). I get that it's making a vector of type char, with each entry being an array of char 4096 bytes large, but I don't get the buffer(fragmentEnd * 3 + 1) part. I think that it confuses me most b/c I can't find where the buffer variable is instantiated anywhere (shouldn't it be something more like Vector<char, 4096> buffer = new Vector<char, 4096>(...)? Thanks in advance

    Read the article

  • Need to interface to a C++ DLL

    - by Pedro
    Hi, I need to call a C++ API from C#. I have been able to call the API, but the char[] parameters do not seem to be marshalling correctly. Here's the C++ signature: Create2ptModel(double modelPowers[2], double modelDacs[2], int pclRange[2], double targetPowers[32], double *dacAdjustFactor, unsigned short powerRampFactors[32], BOOL bPCLDacAdjusted[32], char calibrationModel[32], char errMsg[1024]) and this is how I am trying to call it from C# [DllImport("AlgorithmsLib.dll", EntryPoint = "_Create2ptModel@36", ExactSpelling = true, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)] private static extern AlgorithmStatus Create2ptModel( double[] modelPowers, double[] modelDacs, int[] pclRange, double[] targetPowers, ref double dacAdjustFactor, ushort[] powerRampFactors, bool[] bPCLDacAdjusted, /**/char[] calibrationModel, char[] errMsg/**/); Any idea of how I can marshall it correctly? Thanks in advance!

    Read the article

  • Unwanted character being added to string in C

    - by Church
    I have a program that gives you shipping addresses from an input file. However at the beginning of one of the strings, order.add_one, a number is being added to the beginning of the string, that number is equivalent to the variable "choice" every time. Why is it doing this? #include <stdio.h> #include <math.h> #include <string.h> //structure typedef struct {char cust_name[25]; char cust_id[3]; char add_one[30]; char add_two[30]; char bike; char risky; int number_ordered; char cust_information[500]; }ORDER; ORDER order; int main(void){ fflush(stdin); system ( "clear" ); //initialize variables float price; float m = 359.95; float s = 279.95; //while loop, runs until user declares they no longer wish to input orders while (1==1){ printf("Options: \nEnter Customer information manually : 1 \nSearch Customer by ID(input.txt reader) : 2 \n"); int option = 0; scanf(" %d", &option); if (option == 1){ //Print and scan statements printf("Enter Customer Information\n"); printf("Customer Name: "); scanf(" %[^\n]s", &order.cust_name); printf("\nEnter Address Line One: "); scanf(" %[^\n]s", &order.add_one); printf("\nEnter Addres Line Two: "); scanf(" %[^\n]s", &order.add_two); printf("\nHow Many Bicycles Are Ordered: "); scanf(" %d", &order.number_ordered); printf("\nWhat Type Of Bike Is Ordered\n M Mountain Bike \n S Street Bike"); printf("\nChoose One (M or S): "); scanf(" %c", &order.bike); printf("\nIs The Customer Risky (Y/N): "); scanf(" %c", &order.risky); system ( "clear" ); } if (option == 2){ FILE *fpt; fpt = fopen("input.txt", "r"); if (fpt==NULL){ printf("Text file did not open\n"); return 1; } printf("Enter Customer ID: "); scanf("%s", &order.cust_id); char choice; choice = order.cust_id[0]; char x[3]; int w, u, y, z; char a[10], b[10], c[10], d[10], e[20], f[10], g[10], i[1], j[1]; int h; printf("%s value of c", c); if (choice >='1'){ while ((w = fgetc(fpt)) != '\n' ){ } } if (choice >='2'){ while ((u = fgetc(fpt)) != '\n' ){ } } if (choice >='3'){ while ((y = fgetc(fpt)) != '\n' ){ } } if (choice >= '4'){ while ((z = fgetc(fpt)) != '\n' ){ } } printf("\n"); fscanf(fpt, "%s", x); fscanf(fpt, "%s", a); printf("%s", a); strcat(order.cust_name, a); fscanf(fpt, " %s", b); printf(" %s", b); strcat(order.cust_name, " "); strcat(order.cust_name, b); fscanf(fpt, "%s", c); printf(" %s", c); strcat(order.add_one, "\0"); strcat(order.add_one, c); fscanf(fpt, "%s", d); printf(" %s", d); strcat(order.add_one, " "); strcat(order.add_one, d); fscanf(fpt, "%s", e); printf(" %s", e); strcat(order.add_two, e); fscanf(fpt, "%s", f); printf(" %s", f); strcat(order.add_two, " "); strcat(order.add_two, f); fscanf(fpt, "%s", g); printf(" %s", g); strcat(order.add_two, " "); strcat(order.add_two, g); strcat(order.add_two, "\0"); fscanf(fpt, "%d", &h); printf(" %d", h); order.number_ordered = h; fscanf(fpt, "%s", i); printf(" %s", i); order.bike = i[0]; fscanf(fpt, "%s", j); printf(" %s", j); order.risky = j[0]; fclose(fpt); printf("%s %s %s %d %c %c", order.cust_name, order.add_one, order.add_two, order.number_ordered, order.bike, order.risky); }

    Read the article

  • Convert a number from string to integer without using inbuilt function

    - by Raja
    I am trying this technique but error is coming. Please help me to convert a number from string to integer. #include<iostream> using namespace std; int main() { char *buffer[80]; int a; cout<<"enter the number"; cin.get(buffer,79); char *ptr[80] = &buffer; while(*ptr!='\0') { a=(a*10)+(*ptr-48); } cout<<"the value"<<a; delete ptr[]; return 0; } Errors are: error C2440: 'initializing' : cannot convert from 'char ()[80]' to 'char *[80]' error C2440: '=' : cannot convert from 'char *' to 'int'

    Read the article

  • I need to create a very large array of bits/boolean values. How would I do this in C/C++?

    - by Eddy
    Is it even possible to create an array of bits with more than 100000000 elements? If it is, how would I go about doing this? I know that for a char array I can do this: char* array; array = (char*)malloc(100000000 * sizeof(char)); If I was to declare the array by char array[100000000] then I would get a segmentation fault, since the maximum number of elements has been exceeded, which is why I use malloc. Is there something similar I can do for an array of bits?

    Read the article

  • phpMyAdmin "No database selected" MySQL

    - by user1751660
    I downloaded a MySQL backup file and promptly imported into MAMP's phpMyAdmin. I got this return: Error SQL query: -- -- Database: `mysql` -- -- -------------------------------------------------------- -- -- Table structure for table `columns_priv` -- CREATE TABLE IF NOT EXISTS `columns_priv` ( `Host` CHAR( 60 ) COLLATE utf8_bin NOT NULL DEFAULT '', `Db` CHAR( 64 ) COLLATE utf8_bin NOT NULL DEFAULT '', `User` CHAR( 16 ) COLLATE utf8_bin NOT NULL DEFAULT '', `Table_name` CHAR( 64 ) COLLATE utf8_bin NOT NULL DEFAULT '', `Column_name` CHAR( 64 ) COLLATE utf8_bin NOT NULL DEFAULT '', `Timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP , `Column_priv` SET( 'Select', 'Insert', 'Update', 'References' ) CHARACTER SET utf8 NOT NULL DEFAULT '', PRIMARY KEY ( `Host` , `Db` , `User` , `Table_name` , `Column_name` ) ) ENGINE = MYISAM DEFAULT CHARSET = utf8 COLLATE = utf8_bin COMMENT = 'Column privileges'; MySQL said: #1046 - No database selected I did not alter the .sql file at all. Any hints on how i can get this puppy going locally? Thanks!

    Read the article

  • malloc unable to assign memory + doesnt warn

    - by sraddhaj
    char *str=NULL; strsave(s,str,n+1); printf("%s",str-n); when I gdb debug this code I find that the str value is 0x0 which is null and also that my code is not catching this failed memory allocation , it doesnt execute str==NULL perror code ...Any idea void strsave(char *s,char *str,int n) { str=(char *)malloc(sizeof(char)* n); if(str==NULL) perror("failed to allocate memory"); while(*s) { *str++=*s++; } *str='\0'; }

    Read the article

  • finding character in string C language

    - by iSight
    Hi, I am searching a character at first occurence in string using the following code. But, it is taking some time when the character is too long or the character that i am searching is at far extend, which makes delay in other operations. How could i tackle with this problem. The code is below here. Note: attrPtr is a char* which holds a reference to a string containing '"' character at far extend. int position = 0; char qolon = '"';//character to search while (*(attrPtr + position++) != qolon); char* attrValue = NULL; attrValue = (char*)malloc(position * sizeof(char)); strncpy(attrValue, attrPtr, position-1);

    Read the article

  • Using an int as the numerical representation of a string in C#

    - by bluewall21
    I'm trying to use an integer as the numerical representation of a string, for example, storing "ABCD" as 0x41424344. However, when it comes to output, I've got to convert the integer back into 4 ASCII characters. Right now, I'm using bit shifts and masking, as follows: int value = 0x41424344; string s = new string ( new char [] { (char)(value >> 24), (char)(value >> 16 & 0xFF), (char)(value >> 8 & 0xFF), (char)(value & 0xFF) }); Is there a cleaner way to do this? I've tried various casts, but the compiler, as expected, complained about it.

    Read the article

  • Loop crashing program having to do with 2D arrays

    - by user450062
    I am creating an encoding program and when I instruct the program to create a 5X5 grid based on the alphabet while skipping over letters that match up to certain pre-defined variables(which are given values by user input during runtime). I have a loop that instructs the loop to keep running until the values that access the array are out of bounds, the loop seems to cause the problem. This code is standardized so there shouldn't be much trouble compiling it in another compiler. Also would it be better to seperate my program into functions? here is the code: #include<iostream> #include<fstream> #include<cstdlib> #include<string> #include<limits> using namespace std; int main(){ while (!cin.fail()) { char type[81]; char filename[20]; char key [5]; char f[2] = "q"; char g[2] = "q"; char h[2] = "q"; char i[2] = "q"; char j[2] = "q"; char k[2] = "q"; char l[2] = "q"; int a = 1; int b = 1; int c = 1; int d = 1; int e = 1; string cipherarraytemplate[5][5]= { {"a","b","c","d","e"}, {"f","g","h","i","j"}, {"k","l","m","n","o"}, {"p","r","s","t","u"}, {"v","w","x","y","z"} }; string cipherarray[5][5]= { {"a","b","c","d","e"}, {"f","g","h","i","j"}, {"k","l","m","n","o"}, {"p","r","s","t","u"}, {"v","w","x","y","z"} }; cout<<"Enter the name of a file you want to create.\n"; cin>>filename; ofstream outFile; outFile.open(filename); outFile<<fixed; outFile.precision(2); outFile.setf(ios_base::showpoint); cin.ignore(std::numeric_limits<int>::max(),'\n'); cout<<"enter your codeword(codeword can have no repeating letters)\n"; cin>>key; while (key[a] != '\0' ){ while(b < 6){ cipherarray[b][c] = key[a]; if ( f == "q" ) { cipherarray[b][c] = f; } if ( f != "q" && g == "q" ) { cipherarray[b][c] = g; } if ( g != "q" && h == "q" ) { cipherarray[b][c] = h; } if ( h != "q" && i == "q" ) { cipherarray[b][c] = i; } if ( i != "q" && j == "q" ) { cipherarray[b][c] = j; } if ( j != "q" && k == "q" ) { cipherarray[b][c] = k; } if ( k != "q" && l == "q" ) { cipherarray[b][c] = l; } a++; b++; } c++; b = 1; } while (c < 6 || b < 6){ if (cipherarraytemplate[d][e] == f || cipherarraytemplate[d][e] == g || cipherarraytemplate[d][e] == h || cipherarraytemplate[d][e] == i || cipherarraytemplate[d][e] == j || cipherarraytemplate[d][e] == k || cipherarraytemplate[d][e] == l){ d++; } else { cipherarray[b][c] = cipherarraytemplate[d][e]; d++; b++; } if (d == 6){ d = 1; e++; } if (b == 6){ c++; b = 1; } } cout<<"now enter some text."<<endl<<"To end this program press Crtl-Z\n"; while(!cin.fail()){ cin.getline(type,81); outFile<<type<<endl; } outFile.close(); } } I know there is going to be some mid-forties guy out there who is going to stumble on to this post, he's have been programming for 20-some years and he's going to look at my code and say: "what is this guy doing".

    Read the article

  • Understanding behaviour of read() and write()

    - by neo730
    hi i am a student and just start learning low level c programming.i tried to understand read() and write() methods with this program. #include <unistd.h> #include <stdlib.h> main() { char *st; st=calloc(sizeof(char),2);//allocate memory for 2 char read(0,st,2); write(1,st,2); } i was expecting that it would give segmentation fault when i would try to input more than 2 input characters.but when i execute program and enter " asdf " after giving " as " as output it executes "df" command. i want to know why it doesn't give segmentation fault when we assign more than 2 char to a string of size 2.and why is it executing rest(after 2 char)of input as command instead of giving it as output only? also reading man page of read() i found read() should give EFAULT error,but it doesn't. I am using linux.

    Read the article

  • Why does gcc warn about incompatible struct assignment with a `self = [super initDesignatedInit];' c

    - by gavinbeatty
    I have the following base/derived class setup in Objective-C: @interface ASCIICodeBase : NSObject { @protected char code_[4]; } - (Base *)initWithASCIICode:(const char *)code; @end @implementation ASCIICodeBase - (ASCIICodeBase *)initWithCode:(const char *)code len:(size_t)len { if (len == 0 || len > 3) { return nil; } if (self = [super init]) { memset(code_, 0, 4); strncpy(code_, code, 3); } return self; } @end @interface CountryCode : ASCIICodeBase - (CountryCode *)initWithCode:(const char *)code; @end @implementation CountryCode - (CountryCode *)initWithCode:(const char *)code { size_t len = strlen(code); if (len != 2) { return nil; } self = [super initWithCode:code len:len]; // here return self; } @end On the line marked "here", I get the following gcc warning: warning: incompatible Objective-C types assigning 'struct ASCIICodeBase *', expected 'struct CurrencyCode *' Is there something wrong with this code or should I have the ASCIICodeBase return id? Or maybe use a cast on the "here" line?

    Read the article

  • DATEFROMPARTS

    - by jamiet
    I recently overheard a remark by Greg Low in which he said something akin to "the most interesting parts of a new SQL Server release are the myriad of small things that are in there that make a developer's life easier" (I'm paraphrasing because I can't remember the actual quote but it was something like that). The new DATEFROMPARTS function is a classic example of that . It simply takes three integer parameters and builds a date out of them (if you have used DateSerial in Reporting Services then you'll understand). Take the following code which generates the first and last day of some given years: SELECT 2008 AS Yr INTO #Years UNION ALL SELECT 2009 UNION ALL SELECT 2010 UNION ALL SELECT 2011 UNION ALL SELECT 2012SELECT [FirstDayOfYear] = CONVERT(DATE,CONVERT(CHAR(8),((y.[Yr] * 10000) + 101))),      [LastDayOfYear] = CONVERT(DATE,CONVERT(CHAR(8),((y.[Yr] * 10000) + 1231)))FROM   #Years y here are the results: That code is pretty gnarly though with those CONVERTs in there and, worse, if the character string is constructed in a certain way then it could fail due to localisation, check this out: SET LANGUAGE french;SELECT dt,Month_Name=DATENAME(mm,dt)FROM   (       SELECT  dt = CONVERT(DATETIME,CONVERT(CHAR(4),y.[Yr]) + N'-01-02')       FROM    #Years y       )d;SET LANGUAGE us_english;SELECT dt,Month_Name=DATENAME(mm,dt)FROM   (       SELECT  dt = CONVERT(DATETIME,CONVERT(CHAR(4),y.[Yr]) + N'-01-02')       FROM    #Years y       )d; Notice how the datetime has been converted differently based on the language setting. When French, the string "2012-01-02" gets interpreted as 1st February whereas when us_english the same string is interpreted as 2nd January. Instead of all this CONVERTing nastiness we have DATEFROMPARTS: SELECT [FirstDayOfYear] = DATEFROMPARTS(y.[Yr],1,1),    [LasttDayOfYear] = DATEFROMPARTS(y.[Yr],12,31)FROM   #Years y How much nicer is that? The bad news of course is that you have to upgrade to SQL Server 2012 or migrate to SQL Azure if you want to use it, as is the way of the world! Don't forget that if you want to try this code out on SQL Azure right this second, for free, you can do so by connecting up to AdventureWorks On Azure. You don't even need to have SSMS handy - a browser that runs Silverlight will do just fine. Simply head to https://mhknbn2kdz.database.windows.net/ and use the following credentials: Database AdventureWorks2012 User sqlfamily Password sqlf@m1ly One caveat, SELECT INTO doesn't work on SQL Azure so you'll have to use this instead: DECLARE @y TABLE ( [Yr] INT);INSERT @y([Yr])SELECT 2008 AS Yr UNION ALL SELECT 2009 UNION ALL SELECT 2010 UNION ALL SELECT 2011 UNION ALL SELECT 2012;SELECT [FirstDayOfYear] = DATEFROMPARTS(y.[Yr],1,1),      [LastDayOfYear] = DATEFROMPARTS(y.[Yr],12,31)FROM @y y;SELECT [FirstDayOfYear] = CONVERT(DATE,CONVERT(CHAR(8),((y.[Yr] * 10000) + 101))),      [LastDayOfYear] = CONVERT(DATE,CONVERT(CHAR(8),((y.[Yr] * 10000) + 1231)))FROM @y y; @Jamiet

    Read the article

  • File system with chained clusters

    - by Maki Maki
    I'm trying to create school file system with partitions on disks, every partition has its cluster for her representation. typedef unsigned long ClusterNo; const unsigned long ClusterSize = 2048; int x, y ;//x ,y are entries for two-chained lists of clusters if (endOfFile<maxsize// { ... { pointer = KernelFS::searchFreeCluster(partitionPointer->letter) " How can I initialize the beginning for two clusters, their pointers to be 32 bits?

    Read the article

  • To Obtain EPOCH Time Value from a Packed BIT Structure in C [migrated]

    - by xde0037
    This is not a home assignment! We have a binary data file which has following data structure: (It is a 12 byte structure): I need to find out Epoch time value(total time value is packed in 42 bits as described below): Field-1 : Byte 1, Byte 2, + 6 Bits from Byte 3 Time-1 : 2 Bits from Byte 3 + Byte 4 Time-2 : Byte 5, Byte 6, Byte 7, Byte 8 Field-2 : Byte 9, Byte 10, Byte 11, Byte 12 For Field-1 and Field-2 I do not have issue as they can be taken out easily. I need time value in Epoch Time (long) as it has been packed in Bytes 5,6,7,8 and 3 and 4 as follows: (the bit structure for the time value is as follows): Bytes 5 to 8 (32 bit word) Packs time value bits from 0 thru 31 (byte 5 has 0 to 7 bits, byte 6 has 8 to 15, byte 7 has 16 to 23, byte 8 has 24 to 31). the remaining 10 bits of time value are packed in Bytes 3 and byte 4 as follows: byte 3 has 2 bits:32 and 33, and Byte 4 has remaining bits : 34 to 41. So total bits for time value is 42 bits, packed as above. I need to compute epoch value coming out of these 42 bits. How do I do it? I have done something like this but not sure it gives me correct value: typedef struct P_HEADER { unsigned int tmuNumber : 21; unsigned int time1 : 10; // Bits 6,7 from Byte-3 + 8 bits from Byte-4 unsigned int time2 : 32; // 32 bits: Bytes 5,6,7,8 unsigned int traceKey : 32; } __attribute__((__packed__)) P_HEADER; Then in the code : P_HEADER *header1; //get input string in hexa,etc..etc.. //parse the input with the header as : header1 = (P_HEADER *)inputBuf; // then print the header1->time1, header1->time2 .... long ttime = header1->time1|header1->time2; //?? is this the way to get values out? Any hint tip will be appreciated. Environment is : gcc 4.1, Linux Thanks in advance.

    Read the article

< Previous Page | 41 42 43 44 45 46 47 48 49 50 51 52  | Next Page >