İçeriğe atla
0
  • Ders Ara
  • Ana Sayfa
  • Kategoriler
    • All Categories
      • Individual Categories
    • Gruplar
    • Okunmamış 0
    • Güncel
    • Kullanıcılar
    • Hakkımızda
    • Öğrenci Fırsatları
    • Akademik Takvim
    • CV oluşturucu
    • IEU Timetable
    • Devamsızlık App
    • IEU GPA Hesaplayıcı
    • Niki Cüzdan
    • Ders Ara
    • Ana Sayfa
    • Kategoriler
      • All Categories
        • Individual Categories
      • Gruplar
      • 0 Okunmamış 0
      • Güncel
      • Kullanıcılar
      • Hakkımızda
      • Öğrenci Fırsatları
      • Akademik Takvim
      • CV oluşturucu
      • IEU Timetable
      • Devamsızlık App
      • IEU GPA Hesaplayıcı
      • Niki Cüzdan
      Daralt
      IEU Forum – İzmir Ekonomi Üniversitesi Öğrenci Topluluğu Platformu

      IEU Forum

      -- çevrimiçi
      1. Ana Sayfa
      2. C Programming Language
      3. How to print each line from a string

      Final Unicourse'tan Çalış, Yüksek Notu Garantile!

      %25 İndirim Kodu: FRM25
      Yükleniyor...
      Dersi İzle
      GÖRÜNTÜLEYENLER
      +36
      Premium Özellik
      Bu konuyu kimlerin görüntülediğini görmek için Premium üyelik gerekir.
      Premium'a Geç

      Vizesine Unicourse'tan Çalış, Yüksek Notu Garantile!

      A B C D Çıkmış Sorular Formül Kağıtları Konu Anlatımı Sınav İpuçları Örnek Sınav
      Dersi İzle
      YENİ ÖZELLİK

      Bi'Öğrenci Fırsatları
      Forum'da!

      Bi'Öğrenci ile artık forum üzerinden en güncel indirimlere, anlık fırsatlara ve avantajlı tekliflere ulaşabilirsin.

      FIRSATLARI KEŞFET
      Red Bull Basement
      SPONSORLU ETKİNLİK

      Fikrini Gerçeğe Dönüştür

      Projeni dünyaya göstermek için sahne hazır. Red Bull Basement başvuruları açık.

      Başvurunu Yap

      🎉 Foruma Yeni Özellik Geldi!

      Sizin için PDF toollarını getirdik!

      İncele ve Kullan

      How to print each line from a string

      Konu Zamanlandı Sabitlendi Kilitli Taşındı C Programming Language
      clang
      1 İleti 1 Yayımlayıcılar 0 Bakış
      • En eskiden en yeniye
      • En yeniden en eskiye
      • En çok oylanan
        Cevap
        • Yeni başlık oluşturarak cevapla
        Cevaplamak için giriş yapın
        Bu başlık silindi. Sadece başlık düzenleme yetkisi olan kullanıcılar görebilir.
        • D This user is from outside of this forum
          D This user is from outside of this forum
          dr_robotbones@reddthat.com
          yazdı Son düzenleyen:
          #1

          I'm trying to make some sort of simple console text editor program to get better with C. I'm having trouble with what I thought would be a somewhat simple task:

          How do I get each line from my char* buffer, which contains all of my text, so I can output each line, including empty lines, with the correct line number in front of it.

          I tried several different ways already, but none have stuck. I tried strtok(), which is what is currently pushed to my repo, and it ignores whitespace. I tried strchr() but did not have the slightest idea how that function worked and got an infinite loop. I tried doing my own function to create an array of lines but that lead to a segmentation fault which was not fixed by mallocing the array. I am at a loss here, I'm not sure what I can do.

          Here is the repo: https://codeberg.org/Mister_Bones/txt-ed

          Here is the offending code:

          // Print contents of file
          int print_file(char* buffer) {
          	// Print a new line
          	printf("\n");
          
          	// Print each line with line number
          	// Set first line
          	int line_num = 1;
          
          	// Get individual line from buffer
          	char* line = strtok(buffer, "\n");
          
          	// Loop through and print lines
          	// TODO: Don't ignore whitespace
          	while (line != NULL) {
          		printf("%4d\t%s\n", line_num, line);
          		line = strtok(NULL, "\n");
          		line_num++;
          	}
          
          	return 0;
          }
          
          1 Cevap Son cevap
          1

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Kayıt Ol Giriş
          Cevap
          • Yeni başlık oluşturarak cevapla
          Cevaplamak için giriş yapın
          • En eskiden en yeniye
          • En yeniden en eskiye
          • En çok oylanan


            Önerilen Başlıklar

            • L

              The Wrong Memory: a practical guide to C memory bugs

              Takip ediliyor Susturulmuş Konu Zamanlandı Sabitlendi Kilitli Taşındı C Programming Language clang
              1
              1 Oy
              1 İleti
              0 Bakış
              Kimse yanıtlamadı

            Developed by Enes Uysal & Kadir Ay

            9

            Çevrimiçi

            8.8k

            Kullanıcı

            1.9k

            Konu

            3.7k

            İleti
            • Giriş

            • Hesabınız yok mu? Kayıt Ol

            • Aramak için giriş yapın veya kaydolun
            • İlk ileti
              Son ileti