int main () { char *url = "http://sample.com/foo bar ish "; printf ("%s\n", url); printf ("%s\n", replace_spaces (url)); }
gboolean mouse_ps(GtkWidget *widget, GdkEventButton *event, gpointer data) { gchar *ps; if(event->type == GDK_BUTTON_PRESS && event->button == 3) // right click { ui_toggle_ps_mode(); return FALSE; } if(!tuner.rds_ps_avail) { return FALSE; } if(conf.replace_spaces) { ps = replace_spaces(tuner.rds_ps); gtk_clipboard_set_text(gtk_widget_get_clipboard(ui.window, GDK_SELECTION_CLIPBOARD), ps, -1); g_free(ps); } else { gtk_clipboard_set_text(gtk_widget_get_clipboard(ui.window, GDK_SELECTION_CLIPBOARD), tuner.rds_ps, -1); } return TRUE; }
int main(int argc, char** argv) { char * str = argv[1]; char *str2 = "This is a big string fdsaffds.fdsfds"; replace_spaces(str2, 19); reverse(str); printf("%s", str2); }
static void get_extensions(QSP_ARG_DECL Platform_Device *pdp) { cl_int status; size_t psize; char *extensions; // Check for other properties... // find out how much space required... status = clGetDeviceInfo(PFDEV_OCL_DEV_ID(pdp),CL_DEVICE_EXTENSIONS,0,NULL,&psize); OCL_STATUS_CHECK(status,clGetDeviceInfo) extensions = getbuf(psize+1); status = clGetDeviceInfo(PFDEV_OCL_DEV_ID(pdp),CL_DEVICE_EXTENSIONS,psize+1,extensions,&psize); OCL_STATUS_CHECK(status,clGetDeviceInfo) // change spaces to newlines for easier reading... replace_spaces(extensions,'\n'); SET_OCLDEV_EXTENSIONS(pdp,extensions); }
int main(int argc, char* argv[]) { if (argc < 2) { std::cerr << "You must provide at least one string." << std::endl; } else { for(int i = 1; i < argc; i++) { std::string original = std::string(argv[i]); char* replacement = replace_spaces(argv[i]); std::cout << "\"" << original << "\" replaced " << "\"" << replacement << "\"" << '\n'; if(replacement != argv[i]) delete [] replacement; } std::cout << std::endl; } return 0; }
gboolean mouse_rt(GtkWidget *widget, GdkEvent *event, gpointer data) { gchar *str; if(conf.replace_spaces) { str = replace_spaces((gchar*)data); gtk_clipboard_set_text(gtk_widget_get_clipboard(ui.window,GDK_SELECTION_CLIPBOARD), str, -1); g_free(str); } else { gtk_clipboard_set_text(gtk_widget_get_clipboard(ui.window, GDK_SELECTION_CLIPBOARD), (gchar*)data, -1); } return FALSE; }
gboolean mouse_freq(GtkWidget *widget, GdkEvent *event, gpointer nothing) { const gchar *freq_text = gtk_label_get_text(GTK_LABEL(ui.l_freq)); const gchar *pi_text = gtk_label_get_text(GTK_LABEL(ui.l_pi)); gchar buff[30]; gchar *ps; if(tuner.rds_ps_avail) { if(conf.replace_spaces) { ps = replace_spaces(tuner.rds_ps); g_snprintf(buff, sizeof(buff), "%s %s %s", freq_text, pi_text, ps); g_free(ps); } else { g_snprintf(buff, sizeof(buff), "%s %s %s", freq_text, pi_text, tuner.rds_ps); } } else if(tuner.rds_pi >= 0) { g_snprintf(buff, sizeof(buff), "%s %s", freq_text, pi_text); } else { g_snprintf(buff, sizeof(buff), "%s", freq_text); } gtk_clipboard_set_text(gtk_widget_get_clipboard(ui.window, GDK_SELECTION_CLIPBOARD), buff, -1); return TRUE; }
static Platform_Device * create_ocl_device(QSP_ARG_DECL cl_device_id dev_id, Compute_Platform *cpp) { char *name; //size_t psize; const char *name_p; #define SCRATCH_LEN 128 char scratch[SCRATCH_LEN]; Platform_Device *pdp; name = get_ocl_device_name(QSP_ARG dev_id); if( name == NULL ) return NULL; replace_spaces(name,'_'); /* We might have two of the same devices installed in a single system. * In this case, we can't use the device name twice, because there will * be a conflict. The first one gets the name, then we have to check and * make sure that the name is not in use already. If it is, then we append * a number to the string... */ name_p = available_ocl_device_name(QSP_ARG name,scratch,SCRATCH_LEN); // use cname as scratch string pdp = new_pfdev(name_p); givbuf(name); // initialize all the fields? assert( pdp != NULL ); if( pdp != NULL ){ SET_PFDEV_PLATFORM(pdp,cpp); // allocate the memory for the platform-specific data SET_PFDEV_ODI(pdp,getbuf(sizeof(*PFDEV_ODI(pdp)))); SET_PFDEV_OCL_DEV_ID(pdp,dev_id); } return pdp; }
char* generate_api_url(const char *title, const int year) { size_t titleLength, yearLength, newSize; char *url; char *newTitle = replace_spaces(title); if (newTitle == NULL) return NULL; titleLength = strlen(newTitle); yearLength = (year == 0) ? 1 : 4; newSize = API_URL_LENGTH + titleLength + yearLength; url = (char*)malloc(newSize + 1); if (url == NULL) return NULL; url[newSize] = '\0'; sprintf(url, API_URL, newTitle, year); return url; }
int main() { /*char c;*/ int choice; int n; char str[] = "gee ks f or g ee ks "; char path[128]; char S[128], T[128]; char *pattern = "-20"; char str1[32], str2[32]; char **s; /*do {*/ printf("MENU OPTIONS\n"); printf("1 -- remove spaces from string\n"); printf("2-- Check if a given sequence of moves for a robot is circular or not\n"); printf("3 -- Regex matching problem\n"); printf("4 -- Palindrome detection with non-alphanumeric characters\n"); printf("5 -- Normalize the path\n"); printf("6 -- replace space by percentage20 in a string\n"); printf("7 -- minimum window substring\n"); printf("8 -- integer to english words\n"); printf("9 -- restore IP addresses\n"); printf("10 -- check if strings are isomorphic\n"); printf("11 -- function to determine if a string is a valid number without using any built-in function\n"); printf("12 -- reverse string\n"); printf("13 -- reverse words in a sentence\n"); printf("14 -- shortest distance between words\n"); printf("15 -- shortest distance between words\n"); printf("\n"); printf("Enter your choice\n"); scanf("%d",&choice); switch(choice){ case 1: removeSpaces(str); printf("%s", str); break; case 2: printf("Enter path\n"); scanf("%s", path); printf("path is circular: %s", checkCircularpath(path)?"yes":"no"); break; case 4: palindrome(); break; case 5: printf("Enter path\n"); fgets(path, 128, stdin); printf("Normalized path: %s\n", normalize(path)); break; case 6: memset(path, '\0', 128); printf("Enter string\n"); scanf("%s", path); /*gets(path);*/ replace_spaces(path, pattern); printf("%s\n", path); break; case 7: printf("Enter the string\n"); scanf("%s", S); printf("Enter the pattern\n"); scanf("%s", T); min_window_substring(S, T); break; case 8: /*interger_to_english_words();*/ break; case 9: restore_ip_address(); break; case 10: printf("Enter strings of equal length\n"); printf("Enter string 1\n"); scanf("%s", S); printf("Enter string 2\n"); scanf("%s", T); printf("Strings are isomorphic : %s\n", isomorphic_strings(S, T)?"Yes":"No"); break; case 11: printf("Enter the string\n"); scanf(" %[^\n]s", S); //reading a space through scanf /*fgets(stdin, S, sizeof(S));*/ printf("Is number : %s\n", is_valid_number(S)?"yes":"no"); break; case 12: printf("Enter the string\n"); scanf(" %[^\n]s", S); //make scanf work with spaces //make scanf work with spaces reverse_string(S, strlen(S)); print_string(S, strlen(S)); break; case 13: printf("Enter the sentence\n"); scanf(" %[^\n]s", S); //make scanf work with spaces //make scanf work with spaces /*fgets(S, 128, stdin);*/ reverse_words(S); print_string(S, strlen(S)); break; case 14: printf("Enter number of words\n"); scanf("%d", &n); s = create_2Dchar_array(n, 128); input_2Dchar_array(s, n, 128); printf("enter word 1\n"); scanf("%s", str1); printf("enter word 2\n"); scanf("%s", str2); printf("Shortest distance between %s and %s : %d\n", str1, str2, shortest_distance(s, n, str1, str2)); break; default: printf("Invalid option\n"); break; } printf("\n\n"); /*}while((c=getchar())!='q'); */ return 0; }