c

Loading a font from a file to pango?

不羁岁月 提交于 2021-02-20 11:22:33
问题 I have a code uses Cairo and Pango to create an image : #include<stdio.h> #include<cairo.h> #include<pango/pangocairo.h> #define IMAGE_WIDTH 650 #define IMAGE_HEIGHT 150 #define TEXT "HELLO WORLD" #define FONT "MizuFontAlphabet Normal 40" /* * $ gcc $(pkg-config pangocairo cairo --cflags --libs) file.c */ int main(int argc , char** argv) { cairo_surface_t *surface; cairo_t *cr; PangoLayout *layout; PangoFontDescription *desc; PangoRectangle extents; surface = cairo_image_surface_create(CAIRO

Why do both `htons` and `ntohs` exist?

五迷三道 提交于 2021-02-20 10:12:57
问题 I am not sure why htons and ntohs both exist in the standard library. They do exactly the same thing -- unless I'm confused somehow! The same goes for htonl and ntohl . 回答1: They make for self-documenting code that tells the reader whether the data is in host- or network- order. 回答2: This is in case a machine has some sort of unusual endianness besides big-endian or little-endian that isn't one or more simple byte swaps. For example, if the value 0x0A0B0C0D was represented internally as 0B 0C

Why do both `htons` and `ntohs` exist?

安稳与你 提交于 2021-02-20 10:11:14
问题 I am not sure why htons and ntohs both exist in the standard library. They do exactly the same thing -- unless I'm confused somehow! The same goes for htonl and ntohl . 回答1: They make for self-documenting code that tells the reader whether the data is in host- or network- order. 回答2: This is in case a machine has some sort of unusual endianness besides big-endian or little-endian that isn't one or more simple byte swaps. For example, if the value 0x0A0B0C0D was represented internally as 0B 0C

Is a redeclaration of an untagged structure a compatible type?

十年热恋 提交于 2021-02-20 06:12:43
问题 For purposes expressed in this question, we want to do this: typedef struct { int a; } A; typedef struct { struct { int a; }; int b; } B; A *BToA(B *b) { return (A *) b; } B *AToB(A *a) { return (B *) a; } The desire is that the casts conform to C 2011 6.7.2.1 15, which says “A pointer to a structure object, suitably converted, points to its initial member (or if that member is a bit-field, then to the unit in which it resides), and vice versa.” Since the struct { int a; } inside B does not

How can I test if all bits are set or all bits are not?

房东的猫 提交于 2021-02-20 06:11:30
问题 Using bitwise operator how can I test if the n least significant bits of an integer are either all sets or all not sets. For example if n = 3 I only care about the 3 least significant bits the test should return true for 0 and 7 and false for all other values between 0 and 7. Of course I could do if x = 0 or x = 7 , but I would prefer something using bitwise operators. Bonus points if the technique can be adapted to take into accounts all the bits defined by a mask. Clarification : If I

Are C multidimensional arrays contiguous without holes?

六眼飞鱼酱① 提交于 2021-02-20 05:59:51
问题 I am unable to find in the C standard docs specifically where it says that multidimensional arrays are contiguous. While it can be inferred from the fact that array elements are contiguous, I want some perspective from the community. The following code prints out the numbers in the order that I would expect, which is 1 - 9. #include <stdio.h> int main() { int a[][3] = {{1,2,3},{4,5,6},{7,8,9}}; int* p = (int*)a; int i; for (i = 0; i < sizeof(a)/sizeof(int); i++) printf("%d ",p[i]); return 0;

C strip html between <…>

不羁的心 提交于 2021-02-20 05:16:31
问题 How can i strip the HTML from document between and including the <...> tags in a HTML document using C? My current program uses curl to get the contents of the webpage and puts it into a text file, it then reads from the text file and removes the <>, but i am unsure of how to remove everything between those tags. #include <curl/curl.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #define WEBPAGE_URL "http://homepages.paradise.net.nz/adrianfu/index.html"

C strip html between <…>

久未见 提交于 2021-02-20 05:16:22
问题 How can i strip the HTML from document between and including the <...> tags in a HTML document using C? My current program uses curl to get the contents of the webpage and puts it into a text file, it then reads from the text file and removes the <>, but i am unsure of how to remove everything between those tags. #include <curl/curl.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #define WEBPAGE_URL "http://homepages.paradise.net.nz/adrianfu/index.html"

What is the best way to shift data by X bits into and out of a file?

ぐ巨炮叔叔 提交于 2021-02-20 05:14:08
问题 I have a dataset, made up of a mask file, and a data file. the mask file tells the decoder whether there are 8 bits per field present, or 4, for the current offset of the datafile. I need to shift the data out according to the mask, and write the decoded file, with all 8 bits per field. I'm trying to accomplish this in C. void shift_4bits_left(unsigned char* array, unsigned short size) { int i; unsigned char shifted = 0x00; unsigned char overflow = (0xF0 & array[0]) >> 4; for (i = (size - 1);

What is the best way to shift data by X bits into and out of a file?

人盡茶涼 提交于 2021-02-20 05:13:59
问题 I have a dataset, made up of a mask file, and a data file. the mask file tells the decoder whether there are 8 bits per field present, or 4, for the current offset of the datafile. I need to shift the data out according to the mask, and write the decoded file, with all 8 bits per field. I'm trying to accomplish this in C. void shift_4bits_left(unsigned char* array, unsigned short size) { int i; unsigned char shifted = 0x00; unsigned char overflow = (0xF0 & array[0]) >> 4; for (i = (size - 1);